home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d935.lha / MuchMore / src / MuchMore.mod next >
Text File  |  1993-12-20  |  93KB  |  2,802 lines

  1. (*---------------------------------------------------------------------------
  2. :Program.    MuchMore.mod
  3. :Author.     Fridtjof Siebert
  4. :Address.    Nobileweg 67, D-70439 Stuttgart, Germany
  5. :Shortcut.   [fbs]
  6. :Copyright.  Freeware
  7. :Language.   Oberon-2
  8. :Translator. Amiga Oberon Compiler v3.01
  9. :History.   V1.0 summer-88: First very slow internal version             [fbs]
  10. :History.   V1.1 24-Sep-88: First published version                      [fbs]
  11. :History.   V1.2 26-Nov-88: Now displays Filelength & Percentage         [fbs]
  12. :History.        27-Nov-88: Mouse can be used instead of Space/BackSpace [fbs]
  13. :History.   V1.3 29-Apr-89: Strong increase in speed, removed WarpText   [fbs]
  14. :History.        29-Apr-89: Now supports Numeric Keys (Home,PgUp etc.)   [fbs]
  15. :History.        29-Apr-89: Now opens Screen as big as gfx.normalDisplay [fbs]
  16. :History.   V1.4 29/30-Apr-89: Asynchronus loading/displaying. Very nice [fbs]
  17. :History.        30-Apr-89, 00:33: Removed bugs in Filelength & L-Command[fbs]
  18. :History.        30-Apr-89, 02:21: Added Find-Command                    [fbs]
  19. :History.        30-Apr-89, 10:30: Scrolling stops when window inactive  [fbs]
  20. :History.        01-May-89: Allocates no more unneeded memory for text   [fbs]
  21. :History.        07-May-89: Allocates even less memory now               [fbs]
  22. :History.        14-May-89: Removed deadlock-bug with Find-Window        [fbs]
  23. :History.   V1.5 25-May-89: Added print feature                          [fbs]
  24. :History.        25-May-89: Removed all imports (apart from Arts)        [fbs]
  25. :History.        26-May-89: inspired by J. Kupfer, I added nk 5 to quit  [fbs]
  26. :History.        26-May-89: Now handle BS correctly                      [fbs]
  27. :History.   V1.6 02-Jul-89: Now supports several fontstyles and colors   [fbs]
  28. :History.   V1.7 03-Jul-89: Is again as fast as it was with 2 colors     [fbs]
  29. :History.        03-Jul-89: Now no more crashes when quitting while print[fbs]
  30. :History.        07-Jul-89: removed bug with texts of length 0           [fbs]
  31. :History.   V1.8 10-Jul-89: small bug in find-command removed            [fbs]
  32. :History.        10-Jul-89: now found strings are highlighted            [fbs]
  33. :History.        14-Jul-89: nk0 to display fileinfo                      [fbs]
  34. :History.   V2.0 06-Aug-89: Ported this to OBERON                        [fbs]
  35. :History.        06-Aug-89: Added ARP-FileRequester                      [fbs]
  36. :History.        07-Aug-89: Added L - (load new file) Command            [fbs]
  37. :History.   V2.1 03-Sep-89: no more gurus if an r/w error occures        [fbs]
  38. :History.        03-Sep-89: MM used to execute CSI-Codes backwards. fixed[fbs]
  39. :History.        03-Sep-89: ping / pong with Shift+Fn / Fn               [fbs]
  40. :History.        03-Sep-89: new command: goto                            [fbs]
  41. :History.   V2.2 05-Sep-89: will run with any keymapping now             [fbs]
  42. :History.   V2.3 17-Sep-89: New command: sleep & Pop-Up feature          [fbs]
  43. :History.        17-Sep-89: "MuchMore -s" will go to sleep immediately   [fbs]
  44. :History.        17-Sep-89: Interprets <CSI>m as <CSI>0m now             [fbs]
  45. :History.   V2.4 17-Sep-89: New command: write block "w"                 [fbs]
  46. :History.        17-Sep-89: rewritten argument parser to allow quotes    [fbs]
  47. :History.   V2.5 18-Sep-89: now uses the 8x8 font set with SetFont       [fbs]
  48. :History.        19-Sep-89: no more scatters memory. Allocates 4K Chunks [fbs]
  49. :History.   V2.6 26-Jun-90: Made MuchMore reentrant                      [fbs]
  50. :History.        26-Jun-90: Opens 1-Plane Screen if memory is rare       [fbs]
  51. :History.        26-Jun-90: Asynchronus fast scrolling with Ctrl-Up/Down [fbs]
  52. :History.        26-Jun-90: Now supports interlaced screens              [fbs]
  53. :History.        08-Aug-90: CLI-Option '-l' to toggle interlaced mode    [fbs]
  54. :History.   V2.7 09-Aug-90: no more RethinkDisplay()s,looks good with 2.0[fbs]
  55. :History.        10-Aug-90: Supports Kick2.0 ASL-FileRequester           [fbs]
  56. :History.   V2.8 26-Dez-90: Leaves space between lines on interl. scrns  [fbs]
  57. :History.   V3.0 04-Jul-91: Supports any non-proportional font now       [fbs]
  58. :History.        04-Jul-91: no more supports '-s' (sleep),was rarely used[fbs]
  59. :History.        04-Jul-91: new Options -f<font> and -s<size> for font   [fbs]
  60. :History.        09-Nov-91: Find works w/ dmouse(window may get inactive)[fbs]
  61. :History.   V3.1 04-Sep-92: Uses Screenmode of Workbench screen          [fbs]
  62. :History.   V3.2 02-Nov-92: Supports non-scrollable screens              [fbs]
  63. :History.        02-Nov-92: Complete redraw doesn't scroll anymore       [fbs]
  64. :History. V3.2.1 24-Dec-92: XPK Support                             (C.Stiens)
  65. :History.        24-Dec-92: New option -p for Password              (C.Stiens)
  66. :History.        24-Dec-92: New option -e for Extra Spacing         (C.Stiens)
  67. :History.        24-Dec-92: New option -c for Screen Colors         (C.Stiens)
  68. :History.        24-Dec-92: Tooltypes                               (C.Stiens)
  69. :History. V3.2.2 08-Jan-93: Doesn't use MyMakeScreen() no more      (C.Stiens)
  70. :History. V3.2.3 08-Feb-93: Now closes Console Device               (C.Stiens)
  71. :History.        08-Feb-93: Non-Scroll Mode didn't work always      (C.Stiens)
  72. :History.        10-Feb-93: ScreenMode Requester                    (C.Stiens)
  73. :History.        10-Feb-93: New Option -s for Scroll Mode           (C.Stiens)
  74. :History.        10-Feb-93: Busy Pointer                            (C.Stiens)
  75. :History.        14-Feb-93: Now evals Tooltypes also on CLI start   (C.Stiens)
  76. :History. V3.2.4 15-Feb-93: Clears Idcmp while Busy                 (C.Stiens)
  77. :History.        15-Feb-93: Bugs in GetString fixed                 (C.Stiens)
  78. :History.        19-Feb-93: More Scrollmodes                        (C.Stiens)
  79. :History.        20-Feb-93: Bug in Type() fixed                     (C.Stiens)
  80. :History. V3.2.5 08-Mar-93: Asynch Scrolling changed                (C.Stiens)
  81. :History.        08-Mar-93: New Option -t for Taskpri               (C.Stiens)
  82. :History.        10-Mar-93: Now uses Dos.ReadArgs if KS 2.04        (C.Stiens)
  83. :History. V3.2.6 19-Mar-93: scrollmode 3 now also scrolls soft      (C.Stiens)
  84. :History.        19-Mar-93: New Option -o for one plane             (C.Stiens)
  85. :History.        19-Mar-93: New Option -a for tab width             (C.Stiens)
  86. :History.        19-Mar-93: Removed QText                           (C.Stiens)
  87. :History.        21-Mar-93: Opens screen with full overscan width   (C.Stiens)
  88. :History.        22-Mar-93: Filename can be on any pos at KS1.3     (C.Stiens)
  89. :History.        27-Mar-93: New Option N=NOOSCAN                    (C.Stiens)
  90. :History. V3.2.7 07-Apr-93: Dont pokes to bitmap no more            (C.Stiens)
  91. :History. V3.2.8 12-Apr-93: New Option B=PLANES                     (C.Stiens)
  92. :History. V3.2.9 12-May-93: Implemented V36 ANSI Codes              (C.Stiens)
  93. :History. 3.2.10 16-May-93: Locale Support                          (C.Stiens)
  94. :History.        16-May-93: DispMode-Requester font-sensitive       (C.Stiens)
  95. :History.   V3.3 21-Jun-93: Code optimised                          (C.Stiens)
  96. :History.        25-Jun-93: Safe quit                               (C.Stiens)
  97. :History.   V3.4 29-Jun-93: Clipboard support                       (C.Stiens)
  98. :History.        29-Jun-93: took version number out of catalog      (C.Stiens)
  99. :History.   V3.5 31-Jul-93: case sensitive search, Boyer-Moore Alg. (C.Stiens)
  100. :History.   V3.6 15-Aug-93: Page up/down with softscroll reimpl.    (C.Stiens)
  101. :History.        16-Aug-93: Flash at EOF/BOF                        (C.Stiens)
  102. :Contents.   A Soft-Scrolling ASCII-File Viewer.
  103. :Remark.     Compile: 'Oberon -svbcrntzdma MuchMore' for short code
  104. :Remark.     Compile: 'Oberon -dma MuchMore' for safe code
  105. :Remark.     Link:    'OLink -dma MuchMore'
  106. ---------------------------------------------------------------------------*)
  107.  
  108. MODULE MuchMore; (* $StackChk- *)
  109.  
  110. IMPORT con:= Console,
  111.        d  := Dos,
  112.        e  := Exec,
  113.        g  := Graphics,
  114.        gt := GadTools,
  115.        I  := Intuition,
  116.        ip := IFFParse,
  117.        ie := InputEvent,
  118.        loc:= Locale,
  119.        str:= Strings,
  120.        u  := Utility,
  121.        ol := OberonLib,
  122.        SYS:= SYSTEM;
  123.  
  124. (*-------------------------------------------------------------------------*)
  125.  
  126. CONST
  127.  
  128.   MuchText = "MuchMore 3.6 © 1993 AMOK\o$VER: muchmore 3.6 (6.9.93)";
  129.   Version = "v3.6";
  130.  
  131.   usage = "Usage: MuchMore [-a#|-b#|-c#{,#}|-e#|-f<font>/#|-l|-o|-p<passwd>|-s#|-t#|file]";
  132.  
  133.  
  134.   MSGOOM        = 0;
  135.   MSGCOS        = 1;
  136.   MSGCOW        = 2;
  137.   MSGCOF        = 3;
  138.   MSGRWERR      = 4;
  139.   MSGRETRYABORT = 5;
  140.   MSGEMPTY      = 6;
  141.   MSGSAVE       = 7;
  142.   MSGUSE        = 8;
  143.   MSGCANCEL     = 9;
  144.   MSGOK         = 10;
  145.   MSGCHOOSESM   = 11;
  146.   MSGINFOFMT    = 12;
  147.   MSGH1         = 13;
  148.   MSGH2         = 14;
  149.   MSGH3         = 15;
  150.   MSGH4         = 16;
  151.   MSGH5         = 17;
  152.   MSGH6         = 18;
  153.   MSGH7         = 19;
  154.   MSGH8         = 20;
  155.   MSGH9         = 21;
  156.   MSGH10        = 22;
  157.   MSGH11        = 23;
  158.   MSGH12        = 24;
  159.   MSGH13        = 25;
  160.   MSGH14        = 26;
  161.   MSGH15        = 27;
  162.   MSGH16        = 28;
  163.   MSGH17        = 29;
  164.   MSGH18        = 30;
  165.   MSGH19        = 31;
  166.   MSGH20        = 32;
  167.   MSGH21        = 33;
  168.   MSGH22        = 34;
  169.   MSGH23        = 35;
  170.  
  171.  
  172.   TYPE
  173.     MSGTYPE = ARRAY 36 OF e.STRPTR;
  174.  
  175.   CONST
  176.  
  177.     MSGS = MSGTYPE(
  178.       SYS.ADR( "Out of memory"      ),
  179.       SYS.ADR( "Can't open screen"  ),
  180.       SYS.ADR( "Can't open window"  ),
  181.       SYS.ADR( "Can't open file"    ),
  182.       SYS.ADR( "Read/Write Error"   ),
  183.       SYS.ADR( "Retry|Abort"        ),
  184.       SYS.ADR( "File empty"         ),
  185.       SYS.ADR( "Save"               ),
  186.       SYS.ADR( "Use"                ),
  187.       SYS.ADR( "Cancel"             ),
  188.       SYS.ADR( " OK "               ),
  189.       SYS.ADR( "Choose Screen Mode:"),
  190.       SYS.ADR( " File: %-30.30s %ld%% (%ld of %ld Bytes) %ld Lines"),
  191.       SYS.ADR( "\x13                \x15  MuchMore %s Commands:  "),
  192.       SYS.ADR( " \x0dSpace\x05,\x0d LMB\x05:         Start / Stop scrolling, Quit at end of file"),
  193.       SYS.ADR( " \x0dBackSpace\x05,\x0d RMB\x05:     Start / Stop scrolling backwards"),
  194.       SYS.ADR( " \x0dUp\x05/\x0dDown\x05:            Move one line \x0dup\x05 or \x0ddown\x05"),
  195.       SYS.ADR( " \x0dShift \x05+\x0d Up\x05/\x0dDn\x05:      Start / Stop quick scrolling \x0dup\x05 or \x0ddown\x05"),
  196.       SYS.ADR( " \x0dControl\x05:            Increase scroll speed"),
  197.       SYS.ADR( " \x0dAlt\x05+\x0dUp\x05/\x0dDn\x05,\x0d PgUp\x05/\x0dDn\x05: Move one page \x0dup\x05 or \x0ddown\x05"),
  198.       SYS.ADR( " \x0dT\x05,\x0d Home \x05/\x0d B\x05,\x0d End\x05:   Goto \x0dt\x05op / \x0db\x05ottom of text"),
  199.       SYS.ADR( " (\x0DShift\x05) \x0DF\x05, \x0DN\x05, \x0DP\x05:    \x0DF\x05ind string (case sensitive), \x0DN\x05ext, \x0DP\x05revious"),
  200.       SYS.ADR( " \x0dShift \x05+\x0d Fn\x05:         Set textmarker #n to current position"),
  201.       SYS.ADR( " \x0dFn\x05:                 Goto marker #n or set marker #n if it wasn't set yet"),
  202.       SYS.ADR( " \x0dG\x05:                  \x0dG\x05oto line"),
  203.       SYS.ADR( " \x0dNK 0\x05:               Display info line"),
  204.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d O\x05:    Print text"),
  205.       SYS.ADR( " \x0dW\x05:                  \x0dW\x05rite block between marker #1 and #2 to file or prt"),
  206.       SYS.ADR( " \x0dL\x05:                  \x0dL\x05oad new text"),
  207.       SYS.ADR( " \x0dHELP\x05,\x0d H\x05:            Show commands"),
  208.       SYS.ADR( " \x0dESC\x05,\x0d Q\x05,\x0d X\x05,\x0d NK 5\x05:\x0d    Q\x05uit"),
  209.       SYS.ADR( "© \x131992 Fridtjof Siebert, Nobileweg 67, D-70439 Stuttgart, Germany"),
  210.       SYS.ADR( "  \x131993 Christian Stiens, Heustiege 2, D-59348 Lüdinghausen, Germany"),
  211.       SYS.ADR( "  \x13Please refer to MuchMore.doc for a detailed copyright notice"),
  212.       SYS.ADR( "  This is another product of the Amiga MODULA & OBERON Klub Stuttgart - \x0d\x13AMOK"),
  213.       SYS.ADR( " \x0dC\x05:                  \x0dC\x05opy block between marker #1 and #2 to clipboard") );
  214.  
  215.  
  216. CONST (* RawKey Codes: *)
  217.  
  218.   ESC   = 45H; HELP  = 5FH;
  219.   UP    = 4CH; DOWN  = 4DH;
  220.   SPACE = 40H; BS    = 41H;
  221.   CR    = 44H; ENTER = 43H;
  222.   NK0   = 0FH; NK1   = 1DH; NK2   = 1EH; NK3   = 1FH;
  223.   NK5   = 2EH; NK7   = 3DH; NK8   = 3EH; NK9   = 3FH;
  224.   F1    = 50H; F10   = 59H;
  225.  
  226.  
  227. CONST
  228.   ShowStackSize = 4096;
  229.   BufferSize = 2048;
  230.  
  231.   w = TRUE;
  232.   f = FALSE;
  233.  
  234.   MyIdcmp = LONGSET{I.inactiveWindow,I.activeWindow,I.rawKey,I.mouseButtons};
  235.  
  236. (* Control codes: *)
  237.   plain    = 11X;
  238.   italic   = 12X;
  239.   bold     = 13X;
  240.   boldit   = 14X;
  241.   ulineon  = 15X;
  242.   ulineoff = 16X;
  243.  
  244.   Italic = 0;
  245.   Bold   = 1;
  246.   Ulin   = 2;
  247.   Inv    = 3;
  248.  
  249. TYPE
  250.   String    = e.STRING;
  251.   StringPtr = e.STRPTR;
  252.   CharPtr   = UNTRACED POINTER TO CHAR;
  253.   LongPtr   = UNTRACED POINTER TO LONGINT;
  254.  
  255.   TextLinePtr = UNTRACED POINTER TO TextLine;
  256.   TextLine = STRUCT
  257.                prev : TextLinePtr;
  258.                next : TextLinePtr;
  259.                len  : INTEGER;
  260.                size : INTEGER;
  261.                text : String;
  262.              END;
  263.  
  264. CONST
  265.   MaxLen = SIZE(String);
  266.  
  267. TYPE
  268.   FileRequesterPtr = UNTRACED POINTER TO FileRequester;
  269.  
  270.   FileRequester = STRUCT
  271.                     hail      : StringPtr;
  272.                     ddef      : StringPtr;
  273.                     ddir      : StringPtr;
  274.                     wind      : I.WindowPtr;
  275.                     funcFlags : SHORTSET;
  276.                     flags2    : SHORTSET;
  277.                     function  : PROCEDURE;
  278.                     reserved2 : LONGINT;
  279.                   END;
  280.  
  281.   WBStartupPtr = UNTRACED POINTER TO STRUCT (message : e.Message)
  282.                    process    : d.ProcessId;
  283.                    segment    : e.BPTR;
  284.                    numArgs    : LONGINT;
  285.                    toolWindow : StringPtr;
  286.                    argList : UNTRACED POINTER TO ARRAY 256 OF STRUCT
  287.                                  lock : d.FileLockPtr;
  288.                                  name : StringPtr;
  289.                              END;
  290.                  END;
  291.  
  292.   DiskObjectPtr = UNTRACED POINTER TO STRUCT
  293.                     magic      : INTEGER;
  294.                     version    : INTEGER;
  295.                     gadget     : I.Gadget;
  296.                     type       : SHORTINT;
  297.                     defaultTool: StringPtr;
  298.                     toolTypes  : e.APTR;
  299.                     currentX   : LONGINT;
  300.                     currentY   : LONGINT;
  301.                     drawerData : e.APTR;
  302.                     toolWindow : StringPtr;
  303.                     stackSize  : LONGINT;
  304.                   END;
  305.  
  306.   Args = STRUCT
  307.            a     : LongPtr;
  308.            b     : LongPtr;
  309.            c     : StringPtr;
  310.            d     : StringPtr;
  311.            e     : LongPtr;
  312.            f     : StringPtr;
  313.            n     : StringPtr;
  314.            o     : StringPtr;
  315.            p     : StringPtr;
  316.            s     : LongPtr;
  317.            t     : LongPtr;
  318.            file  : StringPtr;
  319.          END;
  320.  
  321. (*------  Memory:  ------*)
  322.  
  323. CONST ChunkSize = 16384;          (* size of allocated chunks *)
  324.  
  325. TYPE
  326.   MemChunkPtr = UNTRACED POINTER TO MemChunk;  (* chunklist *)
  327.  
  328.   MemChunk = STRUCT
  329.                prev: MemChunkPtr;     (* link *)
  330.                data: ARRAY ChunkSize OF CHAR; (* ChunkSize Bytes of memory *)
  331.              END;
  332.  
  333.  
  334. (*------  Globals  ------*)
  335.  
  336. VAR
  337.   pub            : I.ScreenPtr;        (* default public screen             *)
  338.   Screen         : I.ScreenPtr;        (* MuchMore's Screen                 *)
  339.   rp             : g.RastPortPtr;      (* Screen's RastPort                 *)
  340.   BM             : g.BitMapPtr;        (* Screen's BitMap                   *)
  341.   id             : LONGINT;            (* Display ID                        *)
  342.   Window         : I.WindowPtr;        (* My window                         *)
  343.   win            : I.WindowPtr;        (* window for Find & Goto            *)
  344.   catalog        : loc.CatalogPtr;     (* The Catalog                       *)
  345.   MyFile         : d.FileHandlePtr;    (* For loading Textfile              *)
  346.   MyAttr         : g.TextAttr;         (* The selected Font attributes      *)
  347.   MyFont         : g.TextFontPtr;      (* The selected Font                 *)
  348.   FontName       : String;             (* My Font Name or                   *)
  349.   FontSize       : INTEGER;            (* My Font Size                      *)
  350.   FirstLine      : TextLinePtr;        (* the topmost Line                  *)
  351.   TopLine        : TextLinePtr;        (* the topmost Line                  *)
  352.   BottomLine     : TextLinePtr;        (* Last Line displayed on Screen     *)
  353.   LoadLine       : TextLinePtr;        (* currently loaded Line             *)
  354.   LastLine       : TextLinePtr;        (* Last element of LineList          *)
  355.   writeText      : TextLine;           (* temp. Text Line                   *)
  356.   Name,OldName   : String;             (* Text's Name                       *)
  357.   option         : String;             (* CLI Option                        *)
  358.   taskpri,oldpri : SHORTINT;           (* Muchmore's Task Priority          *)
  359.   Pens           : String;             (* Screen colors                     *)
  360.   Cols           : ARRAY 4 OF INTEGER; (* Color array for LoadRGB4          *)
  361.   icon           : DiskObjectPtr;      (* info                              *)
  362.   nameptr        : StringPtr;          (* String Pointer                    *)
  363.   chptr          : CharPtr;            (* Char Pointer                      *)
  364.   PStr           : String;             (* The command for Dos.Execute       *)
  365.   Buffer         : UNTRACED POINTER TO ARRAY BufferSize OF CHAR; (* ReadBuf *)
  366.   RQPos          : LONGINT;            (* Position within ReadBuffer        *)
  367.   RQLen          : LONGINT;            (* Number of CHARs in Buffer         *)
  368.   scrollmode     : INTEGER;            (* 0=MakeScreen/MrgCop 1=ScrollVPort *)
  369.   NumLines       : INTEGER;            (* Number of Lines on Screen         *)
  370.   fontWidth,fontHeight: INTEGER;       (* Font size                         *)
  371.   fontBaseLine   : INTEGER;            (* Font base line                    *)
  372.   spacing        : INTEGER;            (* Extra Line Spacing                *)
  373.   NumColumns     : INTEGER;            (* Number of Columns on Screen       *)
  374.   PageHeight     : INTEGER;            (* fontHeight*NumLines               *)
  375.   i,j            : INTEGER;            (* count                             *)
  376.   AnzLines       : LONGINT;            (* Length of Text in Lines           *)
  377.   MyLock,OldDir  : d.FileLockPtr;      (* To Examine and Load File          *)
  378.   oldcd          : d.FileLockPtr;      (* To save old CD                    *)
  379.   FileInfo       : d.FileInfoBlockPtr; (* to get File's length              *)
  380.   FileLength,TextLength: LONGINT;      (* Length of File and Displayed Text *)
  381.   ScreenPos      : INTEGER;            (* actual position within bitmap     *)
  382.   numColors      : INTEGER;            (* Number of Colors                  *)
  383.   ShowTask       : e.TaskPtr;          (* the task that displays the text   *)
  384.   ShowStack      : e.APTR;             (* it's stack                        *)
  385.   ShowTaskRunning: BOOLEAN;            (* is Showtask activated?            *)
  386.   SignalNewData  : BOOLEAN;            (* Signal when new data is loaded    *)
  387.   SignalAllRead  : BOOLEAN;            (* send signal at end of text        *)
  388.   Done           : BOOLEAN;            (* Quit                              *)
  389.   print          : BOOLEAN;            (* print text                        *)
  390.   save           : BOOLEAN;            (* save block?                       *)
  391.   copy           : BOOLEAN;            (* copy block to clipboard?          *)
  392.   NewText        : BOOLEAN;            (* load new text                     *)
  393.   Info           : BOOLEAN;            (* is info currently displayed ?     *)
  394.   modeReq        : BOOLEAN;            (* Show Display Mode Requester?      *)
  395.   Scroll         : BOOLEAN;            (* scrolling or waiting?             *)
  396.   Fast           : BOOLEAN;            (* scroll quick?                     *)
  397.   Sync           : BOOLEAN;            (* scroll very quick?                *)
  398.   lace,oldLace   : BOOLEAN;            (* use interlaced screen?            *)
  399.   Decrunched     : BOOLEAN;            (* Is file decrunched?               *)
  400.   Scrollable     : BOOLEAN;            (* is screen able to scroll?         *)
  401.   noOscan        : BOOLEAN;            (* Open Text-overscan Screen?        *)
  402.   refresh        : BOOLEAN;            (* Refresh Window?                   *)
  403.   oldstyle       : BOOLEAN;            (* Page Up/Down with soft scroll?    *)
  404.   overscanTag    : LONGINT;            (* overscan tag                      *)
  405.   mySigBit       : INTEGER;            (* My SignalBit                      *)
  406.   mySig          : LONGSET;            (* My SignalSet = LONGSET{mySigBit}  *)
  407.   Me             : d.ProcessPtr;       (* my main task                      *)
  408.   MyMsgPtr       : I.IntuiMessagePtr;  (* for receiving Messages            *)
  409.   frame          : INTEGER;            (* Frame Count                       *)
  410.   in,out         : d.FileHandlePtr;    (* i/o for TYPE xxx TO PRT:          *)
  411.   fg,bg          : INTEGER;            (* Text colors                       *)
  412.   oldfg,oldbg    : INTEGER;            (* Old Text colors                   *)
  413.   style          : SHORTSET;           (* Text style                        *)
  414.   CommLine       : UNTRACED POINTER TO ARRAY 1000 OF CHAR;(* the CLI args   *)
  415.   tabw           : INTEGER;            (* Tabulator width                   *)
  416.   rd             : d.RDArgsPtr;        (* For ReadArgs                      *)
  417.   args           : Args;               (* My CLI Args                       *)
  418.   ArgPtr         : StringPtr;          (* to get WBArg                      *)
  419.   wbm            : WBStartupPtr;       (* WBenchMessage                     *)
  420.   ri             : g.RasInfoPtr;       (* Screen's ViewPort's RasInfo       *)
  421.   NuScreen       : I.NewScreen;        (* to open screen                    *)
  422.   dims           : g.DimensionInfo;    (* Dims for KS2.0                    *)
  423.   disp           : g.DisplayInfo;      (* DisplayInfo for KS2.0             *)
  424.   NuWindow       : I.NewWindow;        (* to open window                    *)
  425.   Prefs          : I.Preferences;      (* Preferences (need wbLace)         *)
  426.   StrGadget      : I.Gadget;           (* Gadget for Find-Command           *)
  427.   StrInfo        : I.StringInfo;       (* its special info                  *)
  428.   arp            : e.LibraryPtr;       (* ArpBase                           *)
  429.   asl            : e.LibraryPtr;       (* ASL-librarybase                   *)
  430.   diskFontBase   : e.LibraryPtr;       (* DiskFont-LibraryBase              *)
  431.   xpk            : e.LibraryPtr;       (* XpkMaster-Librarybase             *)
  432.   iconBase       : e.LibraryPtr;       (* Icon-Librarybase                  *)
  433.   body,text,ok   : I.IntuiText;        (* IntuiTexts for AutoRequest        *)
  434.   FR             : FileRequester;      (* The Requester                     *)
  435.   Filename       : String;             (* The Filename (without path)       *)
  436.   Dirname        : String;             (* its path                          *)
  437.   Pattern        : ARRAY 80 OF CHAR;   (* The pattern for Filerequester     *)
  438.   NewDisp        : BOOLEAN;            (* need to rebuild Display ?         *)
  439.   TextMarkers    : ARRAY 10 OF TextLinePtr; (* Marked Positions in text     *)
  440.   FindLine       : TextLinePtr;        (* Last found line                   *)
  441.   KeyMap         : ARRAY 50H OF CHAR;  (* console's KeyMap                  *)
  442.   Password       : String;             (* Password for encrypted texts      *)
  443.   conreq         : e.IOStdReqPtr;      (* Console IO-Request                *)
  444.   console        : e.DevicePtr;        (* the console.device                *)
  445.   ievent         : ie.InputEventPtr;   (* InputEvent to convert keycodes    *)
  446.   WriteName      : String;             (* File to write Block               *)
  447.   savefrom,savesize: LONGINT;          (* How much to save?                 *)
  448.   iff            : ip.IFFHandlePtr;    (* IFF Handle for clipboard copy     *)
  449.   buffer         : UNTRACED POINTER TO CHAR; (* Save buffer                 *)
  450.   MemIndex       : INTEGER;            (* index in current Chunk            *)
  451.   CurChunk       : MemChunkPtr;        (* current chunk                     *)
  452.   c              : CHAR;               (* \ used by GetTextLine();          *)
  453.   le             : INTEGER;            (* / global for speed                *)
  454.  
  455.  
  456. (*-------------------------------------------------------------------------*)
  457.  
  458. (*------  DiskFont Procedure:  ------*)
  459.  
  460. PROCEDURE OpenDiskFont*{diskFontBase,-30}(VAR textAttr{8}: g.TextAttr): g.TextFontPtr;
  461.  
  462.  
  463. (*-------------------------------------------------------------------------*)
  464.  
  465. (*------  Icon Procedures:  ------*)
  466.  
  467. PROCEDURE GetDiskObject {iconBase,- 78}(name{8}        : ARRAY OF CHAR): DiskObjectPtr;
  468. PROCEDURE FreeDiskObject{iconBase,- 90}(diskobj{8}     : DiskObjectPtr);
  469. PROCEDURE FindToolType  {iconBase,- 96}(toolTypes{8}   : e.APTR;
  470.                                         typeName{9}    : ARRAY OF CHAR): StringPtr;
  471. PROCEDURE MatchToolValue{iconBase,-102}(typeString{8}  : ARRAY OF CHAR;
  472.                                         val{9}         : ARRAY OF CHAR): BOOLEAN;
  473.  
  474.  
  475. (*-------------------------------------------------------------------------*)
  476.  
  477.  
  478. PROCEDURE StuffChar; (* $EntryExitCode- *)
  479. BEGIN
  480.   SYS.INLINE(016C0U, 04E75U)
  481. END StuffChar;
  482.  
  483.  
  484. (*-------------------------------------------------------------------------*)
  485.  
  486.  
  487. PROCEDURE LocStr (num: LONGINT): e.STRPTR;
  488. VAR default: e.STRPTR;
  489.  
  490. BEGIN
  491.   default := MSGS[num];
  492.   IF loc.base=NIL THEN RETURN default
  493.                   ELSE RETURN loc.GetCatalogStr(catalog,num,default^) END;
  494. END LocStr;
  495.  
  496.  
  497. (*-----------------------------  Requester:  ------------------------------*)
  498.  
  499.  
  500. PROCEDURE Request(Text: ARRAY OF CHAR); (* $CopyArrays- *)
  501.  
  502. BEGIN
  503.   IF ol.wbStarted THEN
  504.     body.frontPen := 0; body.backPen  := 1;  body.drawMode := g.jam2;
  505.     body.leftEdge := 12; body.topEdge  := 8;
  506.     text := body; ok := body;
  507.     body.iText    := SYS.ADR(MuchText);
  508.     body.nextText := SYS.ADR(text);
  509.     text.iText    := SYS.ADR(Text); text.topEdge := 22;
  510.     ok.leftEdge   := 6; ok.topEdge := 3; ok.iText := LocStr(MSGOK);
  511.     SYS.SETREG(0,I.AutoRequest(NIL,SYS.ADR(body),NIL,SYS.ADR(ok),LONGSET{I.rawKey},LONGSET{},320,65));
  512.   ELSE
  513.     SYS.SETREG(0,d.Write(d.Output(),Text,str.Length(Text)));
  514.     SYS.SETREG(0,d.Write(d.Output(),"\n",1));
  515.   END;
  516.   HALT(d.fail);
  517. END Request;
  518.  
  519.  
  520. PROCEDURE OutOfMemHandler;
  521. VAR es: I.EasyStruct;
  522.  
  523. BEGIN
  524.   IF I.int.libNode.version >= 37 THEN
  525.     es.structSize   := SIZE(I.EasyStruct);
  526.     es.flags        := LONGSET{};
  527.     es.title        := SYS.ADR(MuchText);
  528.     es.textFormat   := LocStr(MSGOOM);
  529.     es.gadgetFormat := LocStr(MSGRETRYABORT);
  530.     IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN
  531.       HALT(d.fail)
  532.     END;
  533.   ELSE
  534.     Request(LocStr(MSGOOM)^);
  535.   END;
  536. END OutOfMemHandler;
  537.  
  538.  
  539. (*-------------------------------------------------------------------------*)
  540.  
  541.  
  542. PROCEDURE AllocLine(sz: INTEGER): TextLinePtr;
  543.  
  544. VAR newchunk: MemChunkPtr;
  545.  
  546. BEGIN
  547.   INC(sz,SIZE(TextLine)-MaxLen); IF ODD(sz) THEN INC(sz) END;
  548.   IF MemIndex+sz<=ChunkSize THEN     (* does mem fit into current chunk ? *)
  549.     INC(MemIndex,sz);                (* increment index in current chunk  *)
  550.   ELSE
  551.     NEW(newchunk);                   (* allocate new chunk                *)
  552.     newchunk.prev := CurChunk;       (* link chunk into list              *)
  553.     CurChunk := newchunk;
  554.     MemIndex := sz;
  555.   END;
  556.   RETURN SYS.ADR(CurChunk.data[MemIndex-sz]);
  557. END AllocLine;
  558.  
  559.  
  560. PROCEDURE DisposeLines();
  561.  
  562. VAR chunk: MemChunkPtr;
  563.  
  564. BEGIN
  565.   WHILE CurChunk#NIL DO
  566.     chunk := CurChunk.prev;
  567.     DISPOSE(CurChunk);
  568.     CurChunk := chunk;
  569.   END;
  570.   MemIndex := ChunkSize;
  571. END DisposeLines;
  572.  
  573.  
  574. (*-------------------------------------------------------------------------*)
  575.  
  576. (* $Debug- *)
  577.  
  578.  
  579. PROCEDURE Busy;
  580.  
  581. (* $DataChip+ *)
  582.  
  583. TYPE Data = ARRAY 36 OF INTEGER;
  584.  
  585. CONST ClockData = Data(
  586.   00000U,00000U,
  587.   00400U,007C0U, 00000U,007C0U, 00100U,00380U, 00000U,007E0U,
  588.   007C0U,01FF8U, 01FF0U,03FECU, 03FF8U,07FDEU, 03FF8U,07FBEU,
  589.   07FFCU,0FF7FU, 07EFCU,0FFFFU, 07FFCU,0FFFFU, 03FF8U,07FFEU,
  590.   03FF8U,07FFEU, 01FF0U,03FFCU, 007C0U,01FF8U, 00000U,007E0U,
  591.   00000U,00000U);
  592.  
  593. BEGIN
  594.   IF Window#NIL THEN
  595.     I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.rawKey,I.mouseButtons});
  596.     I.SetPointer(Window,ClockData,16,16,-6,0);
  597.   END;
  598. END Busy;
  599.  
  600.  
  601. PROCEDURE UnBusy;
  602. BEGIN
  603.   IF Window#NIL THEN
  604.     I.ClearPointer(Window);
  605.     I.OldModifyIDCMP(Window,MyIdcmp);
  606.   END;
  607. END UnBusy;
  608.  
  609.  
  610. (*------  Scroll:  ------*)
  611.  
  612. PROCEDURE MakeThink(sync,fast,always: BOOLEAN);
  613. VAR m: INTEGER;
  614.  
  615. BEGIN
  616.   IF Scrollable THEN
  617.     m := 1;
  618.     IF ~always THEN
  619.       IF lace & ~fast THEN m := 2 END;
  620.       IF ~sync THEN INC(m,m*2) END;
  621.     END;
  622.     IF (m=1) OR (frame MOD m=0) THEN
  623.       CASE scrollmode OF
  624.       | 0: I.MakeScreen(Screen);
  625.            e.Forbid; g.MrgCop(I.ViewAddress()); e.Permit;
  626.            g.WaitTOF;
  627.       | 1: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  628.            g.WaitTOF;
  629.       ELSE
  630.            I.MakeScreen(Screen);
  631.            I.RethinkDisplay();
  632.       END;
  633.     END;
  634.     INC(frame);
  635.     (* $IF OvflChk *)
  636.     frame := frame MOD 16384;
  637.     (* $END *)
  638.   END;
  639. END MakeThink;
  640.  
  641.  
  642. (*------  Clear Display:  ------*)
  643.  
  644. PROCEDURE ClearBitMaps;
  645. BEGIN
  646.   g.SetRast(rp,0);
  647.   IF Scrollable THEN
  648.     ri.ryOffset := 0;
  649.     ScreenPos := 0;
  650.     MakeThink(f,f,w);
  651.   END;
  652. END ClearBitMaps;
  653.  
  654. (*-------------------------------------------------------------------------*)
  655.  
  656. (*------  Read one TextLine into a Variable:  ------*)
  657.  
  658.  
  659. PROCEDURE GetTextLine(): TextLinePtr;
  660. (* returns NIL at EOF *)
  661.  
  662. VAR
  663.   l        : TextLinePtr;
  664.   sz,wd,i,j: INTEGER;
  665.   txt      : ARRAY MaxLen+1 OF CHAR;
  666.   num      : ARRAY 10 OF INTEGER;
  667.   newcol   : BOOLEAN;
  668.   oldstyle : SHORTSET;
  669.  
  670.   PROCEDURE GetCh();
  671.   BEGIN
  672.     IF RQPos=RQLen THEN
  673.       RQLen := d.Read(MyFile,Buffer^,BufferSize);
  674.       IF RQLen<0 THEN Request(LocStr(MSGRWERR)^) END;
  675.       RQPos := 0;
  676.     END;
  677.     IF RQLen=0 THEN c := 0X ELSE
  678.       c := Buffer[RQPos]; IF c=0X THEN c:=1X END;
  679.       INC(RQPos); INC(le);
  680.     END;
  681.   END GetCh;
  682.  
  683. BEGIN
  684.   IF RQLen=0 THEN RETURN NIL END;
  685.   sz := 0; wd := 0; le := 0;
  686.   IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END; INC(sz)
  687.                      ELSE IF Bold IN style THEN txt[sz] := bold; INC(sz) END                      END;
  688.   IF   Ulin IN style     THEN txt[sz] := ulineon; INC(sz) END;
  689.   IF    Inv IN style     THEN txt[sz] := CHR(fg+4*bg+1); INC(sz)
  690.   ELSIF (fg#1) OR (bg#0) THEN txt[sz] := CHR(bg+4*fg+1); INC(sz) END;
  691.   LOOP
  692.     LOOP
  693.       GetCh;
  694.       IF SYS.VAL(CHAR,SYS.VAL(SHORTSET,c)*SHORTSET{0..6})#1BX THEN EXIT END;
  695.       i := -1;
  696.       REPEAT
  697.         GetCh;
  698.         IF (c>=30X) & (c<=39X) THEN
  699.           INC(i); num[i] := 0;
  700.           REPEAT
  701.             num[i] := 10*num[i]+ORD(c)-ORD(30X); GetCh;
  702.           UNTIL (c<30X) OR (c>39X);
  703.         END;
  704.         c := CAP(c);
  705.       UNTIL (c>=3FX(*"?"*)) & (c<=5AX) OR (c=0X) OR (i=9);
  706.       IF c=4DX THEN
  707.         newcol := f; oldstyle := style; j := 0;
  708.         IF i=-1 THEN i:=0; num[0] := 0 END;
  709.         WHILE (i>=j) & (sz<MaxLen-1) DO
  710.           CASE num[j] OF
  711.           0:  style := SHORTSET{}; fg := 1; bg := 0; newcol := w |
  712.           1:  INCL(style,Bold) |
  713.           2:  fg := 2; newcol := w |
  714.           3:  INCL(style,Italic) |
  715.           4:  INCL(style,Ulin) |
  716.           7:  INCL(style,Inv); newcol := w |
  717.           8:  oldfg:=fg; oldbg:=bg; fg:=0; bg:=0; newcol := w |
  718.  
  719.           22: EXCL(style,Bold); fg := 1; newcol := w |
  720.           23: EXCL(style,Italic) |
  721.           24: EXCL(style,Ulin) |
  722.           27: EXCL(style,Inv); newcol := w |
  723.           28: fg:=oldfg; bg:=oldbg; newcol := w |
  724.  
  725.           30..37: fg := (num[j]-30) MOD numColors; (*IF fg>=numColors THEN fg:=numColors-1 END;*) newcol := w |
  726.           39:     fg := 1; newcol := w |
  727.  
  728.           40..47: bg := (num[j]-40) MOD numColors; (*IF bg>=numColors THEN bg:=numColors-1 END;*) newcol := w |
  729.           49:     bg := 0; newcol := w |
  730.  
  731.           ELSE END;
  732.           INC(j);
  733.         END;
  734.         IF (oldstyle#style) & (sz<MaxLen) THEN
  735.           IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END;
  736.                              ELSE IF Bold IN style THEN txt[sz] := bold   ELSE txt[sz] := plain  END;
  737.           END;
  738.           INC(sz);
  739.           IF (Ulin IN style) THEN
  740.             IF ~((Ulin IN oldstyle)) & (sz<MaxLen) THEN
  741.               txt[sz] := ulineon;
  742.               INC(sz);
  743.             END;
  744.           ELSE
  745.             IF (Ulin IN oldstyle) & (sz<MaxLen) THEN
  746.               txt[sz] := ulineoff;
  747.               INC(sz);
  748.             END;
  749.           END;
  750.         END;
  751.         IF newcol & (sz<MaxLen) THEN
  752.           IF Inv IN style THEN txt[sz] := CHR(fg+4*bg+1)
  753.                           ELSE txt[sz] := CHR(bg+4*fg+1) END;
  754.           INC(sz);
  755.         END;
  756.       END;   (* IF c="m" THEN *)
  757.     END;   (* LOOP *)
  758.     CASE c OF
  759.       020X.. 7FX:   txt[sz] := c; INC(sz); INC(wd) |
  760.       0A1X..0FFX:   txt[sz] := c; INC(sz); INC(wd) |
  761.       8X: (* BS *)  IF wd>0 THEN DEC(sz); DEC(wd); END |
  762.       9X: (* TAB *) REPEAT
  763.                       txt[sz] := 20X; INC(sz); INC(wd)
  764.                     UNTIL (sz=MaxLen) OR (wd=NumColumns) OR (sz MOD tabw=0) |
  765.       0A0X:         txt[sz] := 20X; INC(sz); INC(wd) |
  766.       0AX,0X,0CX:   EXIT
  767.     ELSE
  768.     END;
  769.     IF (wd>=NumColumns) OR (sz>=MaxLen) THEN EXIT END;
  770.   END;
  771.   txt[sz] := 0X; INC(sz);
  772.   l := AllocLine(sz);
  773.   l.len := le; l.size:= sz;
  774.   WHILE sz>0 DO DEC(sz); l.text[sz] := txt[sz] END;
  775.   RETURN l;
  776. END GetTextLine;
  777.  
  778.  
  779. (*------  Write Line to Screen:  ------*)
  780.  
  781.  
  782. PROCEDURE Type(pos: INTEGER; line: TextLinePtr);
  783.  
  784. VAR
  785.   style: SHORTSET;
  786.   front,back: SHORTINT;
  787.   c: CHAR;
  788.   last,i,x,y: INTEGER;
  789.   strPtr: StringPtr;
  790.  
  791. BEGIN
  792.   g.SetDrMd(rp,g.jam2);
  793.   IF Scrollable THEN
  794.     g.SetAPen(rp,0);
  795.     y := pos * fontHeight;
  796.     IF ~refresh THEN g.RectFill(rp,0,y,NuScreen.width-1,y+fontHeight-spacing-1) END;
  797.   END;
  798.   i := 0; x := 0; style := SHORTSET{}; front := 1; back := 0;
  799.   LOOP
  800.     WHILE line.text[i] < " " DO
  801.       c := line.text[i];
  802.       IF c=0X THEN EXIT END;
  803.       CASE c OF
  804.       plain   : style := style - SHORTSET{g.bold,g.italic} |
  805.       italic  : EXCL(style,g.bold); INCL(style,g.italic)   |
  806.       bold    : INCL(style,g.bold); EXCL(style,g.italic)   |
  807.       boldit  : style := style + SHORTSET{g.bold,g.italic} |
  808.       ulineon : INCL(style,g.underlined) |
  809.       ulineoff: EXCL(style,g.underlined) |
  810.       1X..10X : DEC(c);
  811.                 front := SHORT(ORD(c)) DIV 4;
  812.                 back  := SHORT(ORD(c)) MOD 4 |
  813.       ELSE END;
  814.       INC(i);
  815.     END;
  816.     strPtr := SYS.ADR(line.text[i]); last := i;
  817.     REPEAT INC(i) UNTIL line.text[i]<" ";
  818.     SYS.SETREG(0,g.SetSoftStyle(rp,style,-SHORTSET{}));
  819.     g.SetAPen(rp,front);
  820.     g.SetBPen(rp,back);
  821.     g.Move(rp,fontWidth*x,fontHeight*pos+fontBaseLine);
  822.     g.Text(rp,strPtr^,i-last);
  823.     INC(x,i-last);
  824.   END;
  825. END Type;
  826.  
  827.  
  828. PROCEDURE CopyScrollLine(pos: INTEGER);
  829. (* Kopiert die an pos geschriebene Zeile auf den entsprechenden
  830.  * DoubleBuffer-Bereich
  831.  * ACHTUNG: Darf nur aufgerufen werden, wenn Scrollable TRUE ist!
  832.  *)
  833.  
  834. VAR
  835.   y,z: INTEGER;
  836.  
  837. BEGIN
  838.   y := pos*fontHeight;
  839.   z := PageHeight;
  840.   IF pos >= NumLines THEN z := -z END;
  841.   SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+z, NuScreen.width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  842. END CopyScrollLine;
  843.  
  844.  
  845. (*------  Copy String to TextLine:  ------*)
  846.  
  847.  
  848. PROCEDURE CopyToWriteText(String: StringPtr);
  849. VAR i,j : INTEGER;
  850.  
  851. BEGIN
  852.   e.CopyMem(String^,writeText.text,MaxLen-1);
  853.   j := 0;
  854.   FOR i := 0 TO SHORT(str.Length(writeText.text))-1 DO
  855.     IF writeText.text[i] >= " " THEN INC(j) END;
  856.     IF j >= NumColumns THEN
  857.       writeText.text[i] := 0X;
  858.       RETURN
  859.     END;
  860.   END;
  861. END CopyToWriteText;
  862.  
  863.  
  864. (*------  Write String to Screen (at any position):  ------*)
  865.  
  866.  
  867. PROCEDURE TypeTo(VAR text: TextLine; pos: INTEGER);
  868.  
  869. BEGIN
  870.   IF pos < NumLines THEN
  871.     IF ~Scrollable THEN
  872.       Type(pos,SYS.ADR(text));
  873.     ELSE
  874.       INC(pos,ScreenPos);
  875.       Type(pos,SYS.ADR(text));
  876.       CopyScrollLine(pos);
  877.     END;
  878.   END;
  879. END TypeTo;
  880.  
  881.  
  882. (*------  Write String to Screen (at any position):  ------*)
  883.  
  884.  
  885. PROCEDURE WriteTo(String: StringPtr; pos: INTEGER);
  886.  
  887. BEGIN
  888.   CopyToWriteText(String);
  889.   TypeTo(writeText,pos);
  890. END WriteTo;
  891.  
  892.  
  893. (*------  Write Line at Bottom of Text:  ------*)
  894.  
  895.  
  896. PROCEDURE AddBottomLine(Line: TextLinePtr; Fast: BOOLEAN);
  897. VAR i,y: INTEGER;
  898.  
  899. BEGIN
  900.   IF ~Scrollable THEN
  901.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  902.     IF Fast THEN
  903.       g.ScrollRaster(rp,0,fontHeight,0,0,NuScreen.width-1,NuScreen.height-1);
  904.       IF Sync THEN g.WaitTOF END;
  905.     ELSE
  906.       i := fontHeight;
  907.       REPEAT
  908.         g.ScrollRaster(rp,0,1,0,0,NuScreen.width-1,NuScreen.height-1);
  909.         IF Sync THEN g.WaitTOF END;
  910.         DEC(i);
  911.       UNTIL i=0;
  912.     END;
  913.     Type(NumLines-1,Line);
  914.   ELSE
  915.     Type(ScreenPos+NumLines,Line);
  916.     y := ScreenPos*fontHeight;
  917.     IF Fast THEN
  918.       INC(ri.ryOffset,fontHeight);
  919.       MakeThink(Sync,w,f);
  920.       SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, NuScreen.width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  921.     ELSE
  922.       i := fontHeight;
  923.       REPEAT
  924.         INC(ri.ryOffset);
  925.         MakeThink(Sync,f,f);
  926.         SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, NuScreen.width,1, 0C0X, SHORTSET{0..7}, NIL));
  927.         INC(y);
  928.         DEC(i);
  929.       UNTIL i=0;
  930.     END;
  931.     INC(ScreenPos);
  932.     IF ScreenPos=NumLines THEN
  933.       ScreenPos := 0;
  934.       ri.ryOffset := 0;
  935.     END;
  936.   END;
  937. END AddBottomLine;
  938.  
  939.  
  940. (*------  Check whether BottomLine.next is NIL or not:  ------*)
  941.  
  942.  
  943. PROCEDURE TryBottomnext(): BOOLEAN;
  944. (* returns TRUE if BottomLine.next#NIL END; *)
  945.  
  946. BEGIN
  947.   IF (BottomLine.next=NIL) & (MyFile#NIL) THEN
  948.     SignalNewData := w;
  949.     SYS.SETREG(0,e.Wait(mySig));
  950.     SignalNewData := f;
  951.   END;
  952.   RETURN BottomLine.next#NIL;
  953. END TryBottomnext;
  954.  
  955.  
  956. (*------  Scroll down one Line:  ------*)
  957.  
  958.  
  959. PROCEDURE ScrollDown(Fast: BOOLEAN);
  960.  
  961. BEGIN
  962.   IF TryBottomnext() THEN
  963.     BottomLine := BottomLine.next;
  964.     INC(AnzLines);
  965.     INC(TextLength,BottomLine.len);
  966.   ELSE RETURN END;
  967.   IF AnzLines >= NumLines THEN TopLine := TopLine.next END;
  968.   AddBottomLine(BottomLine,Fast);
  969. END ScrollDown;
  970.  
  971.  
  972. (*------  Scroll Up one Line:  ------*)
  973.  
  974.  
  975. PROCEDURE ScrUp (Fast: BOOLEAN);
  976. VAR
  977.   i,y: INTEGER;
  978.  
  979. BEGIN
  980.   IF ~Scrollable THEN
  981.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  982.     IF Fast THEN
  983.       g.ScrollRaster(rp,0,-fontHeight,0,0,NuScreen.width-1,NuScreen.height-1);
  984.       IF Sync THEN g.WaitTOF END;
  985.     ELSE
  986.       i := fontHeight;
  987.       REPEAT
  988.         g.ScrollRaster(rp,0,-1,0,0,NuScreen.width-1,NuScreen.height-1);
  989.         IF Sync THEN g.WaitTOF END;
  990.         DEC(i)
  991.       UNTIL i=0;
  992.     END;
  993.     IF TopLine.prev#NIL THEN Type(0,TopLine.prev) ELSE Type(0,FirstLine) END;
  994.   ELSE
  995.     IF ScreenPos=0 THEN
  996.       ri.ryOffset  := NumLines*fontHeight;
  997.       ScreenPos := NumLines;
  998.     END;
  999.     DEC(ScreenPos);
  1000.     IF TopLine.prev#NIL THEN Type(ScreenPos,TopLine.prev) ELSE Type(ScreenPos,FirstLine) END;
  1001.     y := ScreenPos*fontHeight;
  1002.     IF Fast THEN
  1003.       DEC(ri.ryOffset,fontHeight);
  1004.       MakeThink(Sync,w,f);
  1005.       SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, NuScreen.width,fontHeight , 0C0X, SHORTSET{0..7}, NIL));
  1006.     ELSE
  1007.       INC(y,fontHeight);
  1008.       i := fontHeight;
  1009.       REPEAT
  1010.         DEC(ri.ryOffset);
  1011.         MakeThink(Sync,f,f);
  1012.         DEC(y);
  1013.         SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, NuScreen.width,1, 0C0X, SHORTSET{0..7}, NIL));
  1014.         DEC(i);
  1015.       UNTIL i=0;
  1016.     END;
  1017.   END;
  1018. END ScrUp;
  1019.  
  1020.  
  1021. PROCEDURE ScrollUp(Fast: BOOLEAN);
  1022.  
  1023. BEGIN
  1024.   IF (TopLine.prev#NIL) & (TopLine.prev.prev#NIL) THEN
  1025.     TopLine := TopLine.prev;
  1026.     DEC(TextLength,BottomLine.len);
  1027.     DEC(AnzLines);
  1028.     BottomLine := BottomLine.prev;
  1029.     ScrUp(Fast);
  1030.   END;
  1031. END ScrollUp;
  1032.  
  1033.  
  1034. (*------  Undo last AddBottomLine:  ------*)
  1035.  
  1036.  
  1037. PROCEDURE DelLine(Fast: BOOLEAN);
  1038.  
  1039. BEGIN
  1040.   ScrUp(Fast);
  1041.   Info := f;
  1042. END DelLine;
  1043.  
  1044.  
  1045. (*------  Convert String to Integer:  ------*)
  1046.  
  1047. PROCEDURE StrToInt(str: StringPtr; base: INTEGER): LONGINT;
  1048.  
  1049. VAR
  1050.   i,j: INTEGER;
  1051.   num: LONGINT;
  1052.   ch : CHAR;
  1053.   neg: BOOLEAN;
  1054.  
  1055. BEGIN
  1056.   num := 0; i := 0; neg := f;
  1057.   IF  str^[0] = '-'                   THEN str:=SYS.ADR(str[1]); neg := w END;
  1058.   IF  str^[0] = '$'                   THEN str:=SYS.ADR(str[1]); base:=16 END;
  1059.   IF (str^[0]='0')&(CAP(str^[1])='X') THEN str:=SYS.ADR(str[2]); base:=16 END;
  1060.   LOOP
  1061.     IF i=LEN(str^) THEN EXIT END;
  1062.     ch := CAP(str^[i]);
  1063.     IF ch=0X THEN EXIT END;
  1064.     j := ORD(ch);
  1065.     CASE ch OF
  1066.       "0".."9": DEC(j,ORD('0'))   |
  1067.       "A".."F": DEC(j,ORD('A')-10);
  1068.                 IF base=10 THEN base:=16; i:=-1; j:=0; num:=0 END;
  1069.       ELSE EXIT
  1070.     END;
  1071.     num := num * base + j;
  1072.     INC(i);
  1073.   END;
  1074.   IF neg THEN num := -num END;
  1075.   RETURN num
  1076. END StrToInt;
  1077.  
  1078.  
  1079. (*-------------------------------------------------------------------------*)
  1080.  
  1081.  
  1082. PROCEDURE GetStr(name: StringPtr; VAR str: String);
  1083. VAR i: INTEGER;
  1084.  
  1085. BEGIN
  1086.   i := -1;
  1087.   REPEAT
  1088.     INC(i); str[i] := name^[i]
  1089.   UNTIL (name^[i]=0X) OR (i=LEN(str)-1);
  1090.   str[i] := 0X
  1091. END GetStr;
  1092.  
  1093.  
  1094. (*-------------------------------------------------------------------------*)
  1095.  
  1096.  
  1097. PROCEDURE GetLength(t: TextLinePtr);
  1098.  
  1099. BEGIN
  1100.   TextLength := 0; AnzLines := 0;
  1101.   WHILE t#NIL DO INC(AnzLines); INC(TextLength,t.len); t := t.prev END;
  1102. END GetLength;
  1103.  
  1104.  
  1105. (*-------------------------------------------------------------------------*)
  1106.  
  1107.  
  1108. PROCEDURE NewDisplay;
  1109. (* Zeichnet ab BottomLine neu *)
  1110.  
  1111. VAR
  1112.   i: INTEGER;
  1113.   l: TextLinePtr;
  1114.  
  1115. BEGIN
  1116.   IF ~refresh THEN ClearBitMaps END;
  1117.   l := BottomLine.prev;
  1118.   IF l#NIL THEN BottomLine := l END;
  1119.   l := BottomLine;
  1120.   i := NumLines-1;
  1121.   WHILE (i>0) & TryBottomnext() DO
  1122.     BottomLine := BottomLine.next;
  1123.     DEC(i);
  1124.   END;
  1125.   WHILE (i>0) & (l.prev#NIL) DO
  1126.     l := l.prev;
  1127.     DEC(i);
  1128.   END;
  1129.   TopLine := l.next;
  1130.   WHILE i<NumLines DO
  1131.     BottomLine := l;
  1132.     TypeTo(BottomLine^,i);
  1133.     INC(i);
  1134.     l := l.next;
  1135.   END;
  1136.   GetLength(BottomLine);
  1137.   Scroll := f;
  1138. END NewDisplay;
  1139.  
  1140.  
  1141. (*-------------------------------------------------------------------------*)
  1142.  
  1143.  
  1144. PROCEDURE * ShowProc;
  1145.  
  1146. VAR
  1147.   l           : TextLinePtr;
  1148.   Down        : BOOLEAN;          (* Scroll-Direction                  *)
  1149.   Shift       : BOOLEAN;          (* Shifted Keystroke ?               *)
  1150.   Alt         : BOOLEAN;          (* Altered Keystroke ?               *)
  1151.   wasInfo     : BOOLEAN;          (* was Info line displayed ?         *)
  1152.   found       : BOOLEAN;          (* TRUE, if find was successful      *)
  1153.   chr         : CHAR;             (* converted keycode                 *)
  1154.   caseDelta   : SHORTINT;         (* Case sensitive Search?            *)
  1155.   flen        : INTEGER;          (* length of findstring              *)
  1156.   i,j         : INTEGER;          (* Count                             *)
  1157.   Class       : LONGSET;          (* contains Message.class            *)
  1158.   Code        : INTEGER;          (* contains Message.code             *)
  1159.   Qualifier   : SET;              (* contains Message.qualifier        *)
  1160.   Find,FindStr: ARRAY 80 OF CHAR; (* findstring / capital findstring   *)
  1161.   Goto        : ARRAY 10 OF CHAR; (* string containing goto line #     *)
  1162.   li          : LONGINT;          (* longint value of line to go to    *)
  1163.   HiText      : TextLine;         (* Highlited textline                *)
  1164.   OldHiText   : TextLinePtr;      (* original, un-hilited text         *)
  1165.   skipTab     : ARRAY 256 OF INTEGER;(* for Boyer-Moore Alg.           *)
  1166.  
  1167.  
  1168.   PROCEDURE WaitAllRead();
  1169.  
  1170.   BEGIN
  1171.     IF MyFile#NIL THEN
  1172.       Busy;
  1173.       SignalAllRead := w;
  1174.       SYS.SETREG(0,e.Wait(mySig));
  1175.       SignalAllRead := f;
  1176.       UnBusy;
  1177.     END;
  1178.   END WaitAllRead;
  1179.  
  1180.  
  1181.   PROCEDURE HiLite(at,len: INTEGER);
  1182.   (* Hilites len chars of BottomLine.text starting at position at *)
  1183.  
  1184.   VAR
  1185.     c: INTEGER;
  1186.     col: CHAR;
  1187.  
  1188.   BEGIN
  1189.     OldHiText := BottomLine; HiText := OldHiText^; BottomLine := SYS.ADR(HiText);
  1190.     IF at+len+2<MaxLen THEN
  1191.       c := 0; col := 5X;
  1192.       WHILE c<at DO
  1193.         IF HiText.text[c]<CHR(17) THEN col := HiText.text[c] END;
  1194.         INC(c);
  1195.       END;
  1196.       HiText.text[at] := CHR(17-ORD(col));
  1197.       c := at; INC(len,at);
  1198.       WHILE c<len DO
  1199.         HiText.text[c+1] := OldHiText.text[c];
  1200.         INC(c);
  1201.       END;
  1202.       HiText.text[c+1] := col;
  1203.       REPEAT
  1204.         HiText.text[c+2] := OldHiText.text[c];
  1205.         INC(c);
  1206.       UNTIL HiText.text[c-1]=0X;
  1207.     END;
  1208.     IF HiText.next#NIL THEN HiText.next.prev := SYS.ADR(HiText) END;
  1209.     IF HiText.prev#NIL THEN HiText.prev.next := SYS.ADR(HiText) END;
  1210.   END HiLite;
  1211.  
  1212.  
  1213.   PROCEDURE UnHiLite();
  1214.  
  1215.   BEGIN
  1216.     IF HiText.next#NIL THEN HiText.next.prev := OldHiText END;
  1217.     IF HiText.prev#NIL THEN HiText.prev.next := OldHiText END;
  1218.   END UnHiLite;
  1219.  
  1220.  
  1221.   PROCEDURE CalcSkipTab;  (* Make skip-table for Boyer-Moore Alg. *)
  1222.   VAR i,j: INTEGER;
  1223.  
  1224.   BEGIN
  1225.     FOR i := 0 TO 255 DO skipTab[i] := flen END;
  1226.     i := 0;
  1227.     FOR j := flen-1 TO 0 BY -1 DO
  1228.       IF skipTab[ORD(FindStr[j])] = flen THEN
  1229.         skipTab[ORD(FindStr[j])] := i;
  1230.       END;
  1231.       INC(i);
  1232.     END;
  1233.   END CalcSkipTab;
  1234.  
  1235.  
  1236.   PROCEDURE Search(): BOOLEAN;
  1237.   (* Searches string and hilites it if found. Result is TRUE if string found *)
  1238.  
  1239.   VAR ch: CHAR;
  1240.       i,j,t: INTEGER;
  1241.  
  1242.   BEGIN
  1243.     IF flen > BottomLine.size THEN RETURN f END;
  1244.     i := flen-1;
  1245.     FOR j := flen-1 TO 0 BY -1 DO
  1246.       LOOP
  1247.         ch := BottomLine.text[i];
  1248.         CASE ch OF "a".."z","à".."ö","ø".."þ": DEC(ch,caseDelta) ELSE END;
  1249.         IF ch = FindStr[j] THEN EXIT END;
  1250.         t := skipTab[ORD(ch)];
  1251.         IF flen-j > t THEN INC(i,flen-j) ELSE INC(i,t) END;
  1252.         IF i >= BottomLine.size THEN RETURN f END;
  1253.         j := flen-1;
  1254.       END;
  1255.       DEC(i);
  1256.     END;
  1257.     INC(i); IF i<0 THEN RETURN f END;
  1258.     SYS.SETREG(0,TryBottomnext());
  1259.     FindLine := BottomLine;
  1260.     HiLite(i,flen);
  1261.     found := w; RETURN w;
  1262.   END Search;
  1263.  
  1264.  
  1265.   PROCEDURE ShowInfo(Fast: BOOLEAN);
  1266.   VAR IStr : String;
  1267.       fmt  : StringPtr;
  1268.       i    : INTEGER;
  1269.       data : STRUCT name : e.STRPTR;
  1270.                     perc : LONGINT;
  1271.                     tlen : LONGINT;
  1272.                     flen : LONGINT;
  1273.                     lins : LONGINT;
  1274.              END;
  1275.   BEGIN
  1276.     data.name := SYS.ADR(OldName);
  1277.     data.perc := TextLength * 100 DIV FileLength;
  1278.     data.tlen := TextLength;
  1279.     data.flen := FileLength;
  1280.     data.lins := AnzLines-1;
  1281.     fmt := LocStr(MSGINFOFMT);
  1282.     e.RawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(IStr));
  1283.     IStr[0] := 7X; IF numColors<4 THEN IStr[0] := 2X END;
  1284.     i := SHORT(str.Length(IStr));
  1285.     REPEAT IStr[i] := 20X; INC(i) UNTIL (i>=LEN(IStr)-2) OR (i>=NumColumns+2);
  1286.     IStr[i] := 0X;
  1287.     CopyToWriteText(SYS.ADR(IStr));
  1288.     AddBottomLine(SYS.ADR(writeText),Fast);
  1289.     Info := w;
  1290.     Scroll := f;
  1291.   END ShowInfo;
  1292.  
  1293.  
  1294.   PROCEDURE GetString(VAR str: ARRAY OF CHAR; int: BOOLEAN);
  1295.   VAR
  1296.     msg: I.IntuiMessagePtr;
  1297.     class: LONGSET;
  1298.     oldheight: INTEGER;
  1299.  
  1300.   BEGIN
  1301.     MakeThink(f,f,w);
  1302.     Busy;
  1303.     NuWindow.leftEdge    := 100;
  1304.     NuWindow.topEdge     := NuScreen.height DIV 2 - 6;
  1305.     IF Scrollable THEN INC(NuWindow.topEdge,ri.ryOffset) END;
  1306.     NuWindow.width       := NuScreen.width-200;
  1307.     NuWindow.height      := Screen.font.ySize+4;
  1308.     NuWindow.blockPen    := 1;
  1309.     NuWindow.idcmpFlags  := LONGSET{I.gadgetUp,I.activeWindow,I.inactiveWindow};
  1310.     NuWindow.flags       := LONGSET{I.rmbTrap,I.activate,I.noCareRefresh};
  1311.     NuWindow.firstGadget := SYS.ADR(StrGadget);
  1312.     NuWindow.screen      := Screen;
  1313.     NuWindow.type        := I.customScreen;
  1314.     StrGadget.leftEdge   := 4;
  1315.     StrGadget.topEdge    := 2;
  1316.     StrGadget.width      := NuWindow.width-8;
  1317.     StrGadget.height     := NuWindow.height-4;
  1318.     StrGadget.activation := {I.stringCenter,I.relVerify};
  1319.     IF int THEN INCL(StrGadget.activation,I.longint) END;
  1320.     StrGadget.gadgetType := I.strGadget;
  1321.     StrGadget.specialInfo:= SYS.ADR(StrInfo);
  1322.     StrInfo.buffer       := SYS.ADR(str);
  1323.     StrInfo.maxChars     := SHORT(LEN(str))-1;
  1324.     oldheight := Screen.height;
  1325.     IF Scrollable THEN INC(Screen.height,Screen.height) END;
  1326.     win := I.OpenWindow(NuWindow);
  1327.     Screen.height := oldheight;
  1328.     IF win # NIL THEN
  1329.       e.WaitPort(win.userPort);
  1330.       SYS.SETREG(0,I.ActivateGadget(StrGadget,win,NIL));
  1331.       LOOP
  1332.         e.WaitPort(win.userPort);
  1333.         msg := e.GetMsg(win.userPort);
  1334.         IF msg # NIL THEN
  1335.           class := msg.class;
  1336.           e.ReplyMsg(msg);
  1337.           IF (I.gadgetUp IN class) OR (I.inactiveWindow IN class) THEN
  1338.             EXIT
  1339.           END;
  1340.         END;
  1341.       END;
  1342.       I.CloseWindow(win); win := NIL;
  1343.     END;
  1344.     UnBusy;
  1345.     refresh := w; BottomLine := TopLine; NewDisplay; refresh := f;
  1346.   END GetString;
  1347.  
  1348.  
  1349.   PROCEDURE Help; (* executed when HELP or H is pressed *)
  1350.  
  1351.   CONST
  1352.     num = 27;
  1353.  
  1354.   VAR
  1355.     i,j  : INTEGER;
  1356.     help : ARRAY num OF StringPtr;
  1357.     fmt  : StringPtr;
  1358.     data : StringPtr;
  1359.     h1   : String;
  1360.  
  1361.   BEGIN
  1362.     data := SYS.ADR(Version);
  1363.     fmt := LocStr(MSGH1);
  1364.     e.RawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(h1));
  1365.     help[ 0] := SYS.ADR("");    help[ 1] := SYS.ADR(h1);
  1366.     help[ 2] := SYS.ADR("");    help[ 3] := LocStr(MSGH2);
  1367.     help[ 4] := LocStr(MSGH3);  help[ 5] := LocStr(MSGH4);
  1368.     help[ 6] := LocStr(MSGH5);  help[ 7] := LocStr(MSGH6);
  1369.     help[ 8] := LocStr(MSGH7);  help[ 9] := LocStr(MSGH8);
  1370.     help[10] := LocStr(MSGH9);  help[11] := LocStr(MSGH10);
  1371.     help[12] := LocStr(MSGH11); help[13] := LocStr(MSGH12);
  1372.     help[14] := LocStr(MSGH13); help[15] := LocStr(MSGH14);
  1373.     help[16] := LocStr(MSGH23); help[17] := LocStr(MSGH15);
  1374.     help[18] := LocStr(MSGH16); help[19] := LocStr(MSGH17);
  1375.     help[20] := LocStr(MSGH18); help[21] := SYS.ADR("");
  1376.     help[22] := LocStr(MSGH19); help[23] := LocStr(MSGH20);
  1377.     help[24] := LocStr(MSGH21); help[25] := SYS.ADR("");
  1378.     help[26] := LocStr(MSGH22);
  1379.     ClearBitMaps();
  1380.     j := (NumLines - num) DIV 2; IF j<0 THEN j:=0 END;
  1381.     i := 0;
  1382.     WHILE (i<num) & (i+j<NumLines) DO
  1383.       WriteTo(help[i],j+i);
  1384.       INC(i);
  1385.     END;
  1386.     LOOP
  1387.       e.WaitPort(Window.userPort);
  1388.       MyMsgPtr := e.GetMsg(Window.userPort);
  1389.       IF (LONGSET{I.rawKey,I.mouseButtons}*MyMsgPtr.class#LONGSET{}) & (MyMsgPtr.code<128) THEN EXIT END;
  1390.       e.ReplyMsg(MyMsgPtr);
  1391.     END;
  1392.     e.ReplyMsg(MyMsgPtr);
  1393.     BottomLine := TopLine;
  1394.     NewDisplay
  1395.   END Help;
  1396.  
  1397.  
  1398.   PROCEDURE Bottom;  (* executed when END or B is pressed *)
  1399.  
  1400.   BEGIN
  1401.     WaitAllRead;
  1402.     BottomLine := LastLine;
  1403.     NewDisplay
  1404.   END Bottom;
  1405.  
  1406.  
  1407.   PROCEDURE Space(): BOOLEAN;  (* executed if space or LMB is pressed *)
  1408.   (* IF result=w THEN EXIT END *)
  1409.  
  1410.   BEGIN
  1411.     IF (MyFile=NIL) & (BottomLine.next=NIL) THEN        (* End of file? *)
  1412.       IF wasInfo THEN RETURN w END;
  1413.       ShowInfo(Shift);
  1414.     ELSE
  1415.       IF Down THEN
  1416.         Scroll := ~Scroll;
  1417.         IF ~Scroll THEN ShowInfo(Fast) END;
  1418.       ELSE
  1419.         Down := w;
  1420.         Scroll := w;
  1421.       END;
  1422.       Fast := Shift;
  1423.     END;
  1424.     RETURN f;
  1425.   END Space;
  1426.  
  1427.  
  1428.   PROCEDURE BackSpace;  (* executed if backspace or RMB is pressed *)
  1429.  
  1430.   BEGIN
  1431.     Fast := Shift;
  1432.     Scroll := Down OR ~Scroll;
  1433.     Down := f
  1434.   END BackSpace;
  1435.  
  1436.  
  1437. BEGIN
  1438.   (* $IF SmallData *)
  1439.   SYS.SETREG(13,e.exec.thisTask.userData);
  1440.   (* $END *)
  1441.  
  1442.   (* $IFNOT ClearVars *)
  1443.   Find[0] := 0X; FindStr[0] := 0X; Goto[0] := 0X;
  1444.   (* $END *)
  1445.  
  1446.   Down := w;
  1447.  
  1448.   SYS.SETREG(0,e.Wait(mySig));
  1449.  
  1450.   LOOP
  1451.  
  1452.     IF NewDisp THEN NewDisp := f; NewDisplay END;
  1453.  
  1454. (*------  Type Text:  ------*)
  1455.  
  1456.     LOOP
  1457.       IF Scroll THEN
  1458.         IF Down THEN
  1459.           ScrollDown(Fast);
  1460.           Scroll := (MyFile#NIL) OR (BottomLine.next#NIL);
  1461.         ELSE
  1462.           ScrollUp(Fast);
  1463.           Scroll := (TopLine.prev#NIL) & (TopLine.prev.prev#NIL);
  1464.         END;
  1465.       ELSE
  1466.         MakeThink(f,f,w);
  1467.         e.WaitPort(Window.userPort);
  1468.       END;
  1469.  
  1470.       MyMsgPtr := e.GetMsg(Window.userPort);
  1471.  
  1472.       IF (MyMsgPtr#NIL) THEN
  1473.         IF ~(I.inactiveWindow IN MyMsgPtr.class) THEN EXIT END;
  1474.         e.ReplyMsg(MyMsgPtr);
  1475.         I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.mouseButtons});
  1476.         e.WaitPort(Window.userPort);
  1477.         I.OldModifyIDCMP(Window,MyIdcmp);
  1478.       END;
  1479.     END;
  1480.  
  1481.     Code      := MyMsgPtr.code;
  1482.     Class     := MyMsgPtr.class;
  1483.     Qualifier := MyMsgPtr.qualifier;
  1484.  
  1485.     e.ReplyMsg(MyMsgPtr);
  1486.  
  1487.  
  1488.     Shift := {ie.lShift,ie.rShift,ie.capsLock} * Qualifier # {};
  1489.     Alt   := {ie.lAlt  ,ie.rAlt}               * Qualifier # {};
  1490.     Sync  := ~ (ie.control IN Qualifier);
  1491.  
  1492.     IF ~Sync THEN Shift := w END;
  1493.  
  1494.  
  1495.     IF (I.rawKey       IN Class) & (Code<80H) OR
  1496.        (I.mouseButtons IN Class) & ({ie.leftButton,ie.rightButton}*Qualifier#{})
  1497.     THEN
  1498.       wasInfo := f;
  1499.       IF Info THEN DelLine(Shift); wasInfo := w; END;
  1500.     END;
  1501.  
  1502.  
  1503.     IF I.mouseButtons IN Class THEN
  1504.  
  1505.       IF    (ie.leftButton IN Qualifier)   & Space()   THEN EXIT
  1506.       ELSIF ie.rightButton IN Qualifier THEN BackSpace END;
  1507.  
  1508.     ELSIF (I.rawKey IN Class) & (Code<80H) THEN
  1509.  
  1510.       CASE Code OF
  1511.  
  1512.       | SPACE: IF Space() THEN EXIT END                     (* Space *)
  1513.  
  1514.       | BS:    BackSpace                                    (* BackSpace *)
  1515.  
  1516.       | DOWN,NK2,NK3:                                       (* Down *)
  1517.  
  1518.           IF (MyFile=NIL) & (BottomLine.next=NIL) THEN
  1519.             I.DisplayBeep(NIL)
  1520.           ELSE
  1521.             IF Shift & (Code # NK3) THEN
  1522.               Scroll := ~Down OR ~Scroll OR ~Fast;
  1523.               Fast := w; Down := w;
  1524.             ELSE
  1525.               IF Alt OR (Code=NK3) THEN
  1526.                 IF oldstyle THEN
  1527.                   i := NumLines-1;
  1528.                   REPEAT
  1529.                     ScrollDown(w);
  1530.                     DEC(i);
  1531.                   UNTIL i=0;
  1532.                 ELSE
  1533.                   IF BottomLine.next#NIL THEN BottomLine := BottomLine.next END;
  1534.                   NewDisplay;
  1535.                 END;
  1536.               ELSE
  1537.                 ScrollDown(w);
  1538.               END;
  1539.               Scroll := f;
  1540.             END;
  1541.           END;
  1542.  
  1543.       | UP,NK8,NK9:                                        (* Up *)
  1544.  
  1545.           IF (TopLine.prev=NIL) OR (TopLine.prev.prev=NIL) THEN
  1546.             I.DisplayBeep(NIL)
  1547.           ELSE
  1548.             IF Shift & (Code # NK9) THEN
  1549.               Scroll := Down OR ~Scroll OR ~Fast;
  1550.               Fast := w; Down := f;
  1551.             ELSE
  1552.               IF Alt OR (Code=NK9) THEN
  1553.                 i := NumLines-1;
  1554.                 IF oldstyle THEN
  1555.                   REPEAT
  1556.                     ScrollUp(w);
  1557.                     DEC(i);
  1558.                   UNTIL i=0;
  1559.                 ELSE
  1560.                   (*IF TopLine.prev#NIL THEN*)
  1561.                   BottomLine := TopLine;
  1562.                   WHILE (i>0) & (BottomLine.prev#NIL) DO
  1563.                     BottomLine := BottomLine.prev;
  1564.                     DEC(i);
  1565.                   END;
  1566.                   NewDisplay;
  1567.                   (*END;*)
  1568.                 END;
  1569.               ELSE
  1570.                 ScrollUp(w);
  1571.               END;
  1572.               Scroll := f;
  1573.             END;
  1574.           END;
  1575.  
  1576.       | CR,ENTER: ScrollDown(f); Scroll := f;              (* CR *)
  1577.  
  1578.       | NK7: BottomLine := FirstLine; NewDisplay           (* Home *)
  1579.  
  1580.       | NK1: Bottom                                        (* End *)
  1581.  
  1582.       | F1..F10:                                           (* F1..F10 *)
  1583.  
  1584.           i := Code-F1;
  1585.           IF ~ Shift & (TextMarkers[i]#NIL) THEN
  1586.             BottomLine := TextMarkers[i];
  1587.             NewDisplay;
  1588.           ELSE
  1589.             TextMarkers[i] := TopLine;
  1590.           END
  1591.  
  1592.       | NK0:  IF ~wasInfo THEN ShowInfo(Shift) END;        (* NK 0 *)
  1593.  
  1594.       | HELP: Help                                         (* Help *)
  1595.  
  1596.       | ESC:  EXIT                                         (* Quit *)
  1597.  
  1598.       | NK5:  IF wasInfo THEN EXIT ELSE ShowInfo(Shift)END; (* safe Quit *)
  1599.  
  1600.       ELSE
  1601.  
  1602.         IF Code<40H THEN         (* examine vanilla keycode: *)
  1603.  
  1604.           chr := KeyMap[Code];
  1605.  
  1606.           CASE chr OF
  1607.  
  1608.           | "t": BottomLine := FirstLine; NewDisplay       (* Home *)
  1609.  
  1610.           | "b": Bottom;                                   (* End *)
  1611.  
  1612.           | "f","n","p":                                   (* Find, Next, Previous *)
  1613.  
  1614.             IF chr="f" THEN
  1615.               caseDelta := 32; IF Shift THEN caseDelta := 0 END;
  1616.               GetString(Find,f);
  1617.               FindLine := NIL; flen := 0;
  1618.               LOOP
  1619.                 FindStr[flen] := Find[flen];
  1620.                 CASE FindStr[flen] OF
  1621.                   "a".."z","à".."ö","ø".."þ": DEC(FindStr[flen],caseDelta) |
  1622.                   0X: EXIT;
  1623.                 ELSE
  1624.                 END;
  1625.                 INC(flen);
  1626.               END;
  1627.               CalcSkipTab;
  1628.             END;
  1629.             found := f;
  1630.             IF FindStr[0]#0X THEN
  1631.               Busy;
  1632.               i := NumLines;
  1633.               IF FindLine # NIL THEN FindLine := FindLine.next END;
  1634.               WHILE (i>0) & (BottomLine#NIL) & (BottomLine#FindLine) DO
  1635.                 BottomLine := BottomLine.prev; DEC(i);
  1636.               END;
  1637.               IF (BottomLine # FindLine) OR (BottomLine=NIL) THEN
  1638.                 BottomLine := TopLine
  1639.               END;
  1640.               IF chr # "p" THEN                          (* next *)
  1641.                 WHILE (BottomLine # NIL) & ~ Search() DO
  1642.                   SYS.SETREG(0,TryBottomnext());
  1643.                   BottomLine := BottomLine.next;
  1644.                 END;
  1645.               ELSE                                       (* previous *)
  1646.                 IF BottomLine.prev#NIL THEN BottomLine:=BottomLine.prev END;
  1647.                 REPEAT
  1648.                   BottomLine := BottomLine.prev
  1649.                 UNTIL (BottomLine=NIL) OR Search();
  1650.               END;
  1651.               IF BottomLine#NIL THEN
  1652.                 li := NumLines DIV 2;
  1653.                 WHILE (li>0) & (BottomLine.prev#NIL) DO BottomLine := BottomLine.prev; DEC(li) END;
  1654.               END;
  1655.               UnBusy;
  1656.             END;
  1657.  
  1658.             IF ~ found THEN
  1659.               I.DisplayBeep(NIL);
  1660.               BottomLine := TopLine;
  1661.             END;
  1662.             NewDisplay;
  1663.             IF found THEN UnHiLite END;
  1664.  
  1665.           | "w","c":                                       (* write block *)
  1666.             IF (TextMarkers[0]#NIL) & (TextMarkers[1]#NIL) & ~print & ~save THEN
  1667.               savefrom := 0; savesize := 0;
  1668.               l := TextMarkers[0].prev; WHILE l.prev#NIL DO l := l.prev; INC(savefrom,l.len) END;
  1669.               l := TextMarkers[1].prev; WHILE l#NIL DO INC(savesize,l.len); l := l.prev END;
  1670.               l := TextMarkers[1]; i := NumLines; WHILE (i>1) & (l#NIL) DO DEC(i); INC(savesize,LONG(l.len)); l := l.next END;
  1671.               DEC(savesize,savefrom);
  1672.               IF savesize>0 THEN
  1673.                 IF chr="c" THEN copy := w ELSE
  1674.                   GetString(WriteName,f);
  1675.                   copy := f;
  1676.                 END;
  1677.                 WaitAllRead; save := w; e.Signal(SYS.ADR(Me.task),mySig);
  1678.               END
  1679.             END
  1680.  
  1681.           | "o":                                           (* Print *)
  1682.  
  1683.             IF Shift & Alt & ~print & ~save THEN
  1684.               nameptr := SYS.ADR(Name);
  1685.               e.RawDoFmt("TYPE %s TO PRT:",SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1686.               WaitAllRead; print := w; e.Signal(SYS.ADR(Me.task),mySig);
  1687.             END
  1688.  
  1689.           | "l":                                           (* Load Text *)
  1690.  
  1691.             ClearBitMaps;
  1692.             NewText := w; e.Signal(SYS.ADR(Me.task),mySig);
  1693.             REPEAT UNTIL (mySigBit IN e.Wait(mySig)) & ~ NewText |
  1694.  
  1695.           | "g":                                           (* goto *)
  1696.  
  1697.             GetString(Goto,w);
  1698.             li := SHORT(StrInfo.longInt);
  1699.             Busy;
  1700.             BottomLine := FirstLine;
  1701.             WHILE (li>0) & TryBottomnext() DO
  1702.               BottomLine := BottomLine.next;
  1703.               DEC(li)
  1704.             END;
  1705.             UnBusy;
  1706.             NewDisplay
  1707.  
  1708.           | "h":     Help                                  (* Help *)
  1709.  
  1710.           | "q","x": IF wasInfo THEN EXIT ELSE ShowInfo(Shift) END; (* safe Quit *)
  1711.  
  1712.           ELSE END;
  1713.  
  1714.         END;   (* IF Code<40H THEN *)
  1715.  
  1716.       END;   (* CASE Code OF *)
  1717.  
  1718.     END;   (* IF I.rawKey IN Class THEN *)
  1719.  
  1720.   END;   (* LOOP *)
  1721.  
  1722.   Done := w;
  1723.   e.Signal(SYS.ADR(Me.task),mySig);
  1724.   LOOP SYS.SETREG(0,e.Wait(LONGSET{})) END;
  1725.  
  1726. END ShowProc;
  1727.  
  1728. (* $Debug= *)
  1729.  
  1730. (*--------------------------  File Requester:  ----------------------------*)
  1731.  
  1732.  
  1733. PROCEDURE FileReq(VAR Name: String);
  1734.  
  1735. CONST
  1736.   dummy     = u.user + 80000H;
  1737.   taghail   = dummy + 1;
  1738.   window    = dummy + 2;
  1739.   leftEdge  = dummy + 3;         (* Initialize LeftEdge                  *)
  1740.   topEdge   = dummy + 4;         (* Initialize TopEdge                   *)
  1741.   width     = dummy + 5;
  1742.   height    = dummy + 6;
  1743.   hookFunc  = dummy + 7;         (* Hook function pointer                *)
  1744.   file      = dummy + 8;         (* Initial name of file follows         *)
  1745.   dir       = dummy + 9;         (* Initial string for filerequest dir   *)
  1746.   pattern   = dummy + 10;
  1747.   funcFlags = dummy + 20;
  1748.   fiDir     = u.user + 50;
  1749.   longPath  = 0;
  1750.   patGad    = 0;
  1751.  
  1752. VAR
  1753.   fr: FileRequesterPtr;
  1754.   pscr: I.ScreenPtr;
  1755.   i,j: INTEGER;
  1756.   res: BOOLEAN;
  1757.  
  1758.   PROCEDURE AllocAslRequest  {asl,-48} (type{0}: LONGINT;
  1759.                                         tag{8}..: e.APTR): FileRequesterPtr;
  1760.   PROCEDURE FreeAslRequest   {asl,-54} (fr{8}: FileRequesterPtr);
  1761.   PROCEDURE RequestFile      {asl,-42} (fr{8}: FileRequesterPtr): e.APTR;
  1762.  
  1763.   PROCEDURE FileRequest{arp,-294}(VAR filereq{8}: FileRequester): BOOLEAN;
  1764.  
  1765. BEGIN
  1766.   j := SHORT(str.Length(Name));
  1767.   WHILE (j>0) & (Name[j]#":") & (Name[j]#"/") DO DEC(j) END;
  1768.   IF j=0 THEN j := -1 END;
  1769.   i := 0;
  1770.   WHILE i<=j DO Dirname[i] := Name[i]; INC(i) END; Dirname[i] := 0X;
  1771.   j := 0;
  1772.   REPEAT Filename[j] := Name[i]; INC(j); INC(i) UNTIL Name[i-1]=0X;
  1773.  
  1774.   LOOP
  1775.     IF I.int.libNode.version >= 37 THEN
  1776.       pscr := I.LockPubScreen(NIL);
  1777.       IF pscr#NIL THEN
  1778.         I.ScreenToFront(pscr);
  1779.         I.UnlockPubScreen(NIL,pscr);
  1780.         EXIT
  1781.       END;
  1782.     END;
  1783.     SYS.SETREG(0,I.WBenchToFront());
  1784.     EXIT
  1785.   END;
  1786.  
  1787.   IF asl=NIL THEN asl := e.OpenLibrary("asl.library",36) END;
  1788.   IF asl#NIL THEN
  1789.     fr := AllocAslRequest(0,taghail, SYS.ADR(MuchText),
  1790.                             file,    SYS.ADR(Filename),
  1791.                             dir,     SYS.ADR(Dirname),
  1792.                             pattern, SYS.ADR(Pattern),
  1793.                             funcFlags,ASH(1,patGad),
  1794.                             u.done);
  1795.     IF fr=NIL THEN Request(LocStr(MSGOOM)^) END;
  1796.     res := RequestFile(fr)#NIL;
  1797.     IF res THEN
  1798.       Filename := fr.ddef^;
  1799.       Dirname  := fr.ddir^;
  1800.     END;
  1801.     FreeAslRequest(fr);
  1802.     IF ~res THEN HALT(d.ok) END;
  1803.   ELSE
  1804.     IF arp=NIL THEN arp := e.OpenLibrary("arp.library",39) END;
  1805.     IF arp#NIL THEN
  1806.       FR.hail := SYS.ADR(MuchText);
  1807.       FR.ddef := SYS.ADR(Filename);
  1808.       FR.ddir := SYS.ADR(Dirname);
  1809.       FR.flags2 := SHORTSET{longPath};
  1810.       FR.wind := NIL;
  1811.       IF ~FileRequest(FR) THEN HALT(d.ok) END;
  1812.     ELSE
  1813.       Request("Need ARP for filereq")
  1814.     END;
  1815.   END;
  1816.   Name := Dirname;
  1817.   i := SHORT(str.Length(Name));
  1818.   IF (i>0) THEN
  1819.     CASE Name[i-1] OF "/",":": ELSE
  1820.       Name[i] := "/"; INC(i);
  1821.     END;
  1822.   END;
  1823.   j := 0;
  1824.   LOOP
  1825.     Name[i] := Filename[j];
  1826.     IF (Name[i]=0X) OR (i=255) THEN EXIT END;
  1827.     INC(i);
  1828.     INC(j);
  1829.   END;
  1830.   Name[i] := 0X;
  1831.   IF Screen#NIL THEN I.ScreenToFront(Screen) END;
  1832.   IF Window#NIL THEN IF I.ActivateWindow(Window) THEN END END;
  1833. END FileReq;
  1834.  
  1835.  
  1836. (*--------------------------  Decrunch:  ----------------------------*)
  1837.  
  1838.  
  1839. PROCEDURE DirExists(name: ARRAY OF CHAR): BOOLEAN; (* $CopyArrays- *)
  1840. VAR lock: d.FileLockPtr;
  1841.     result: BOOLEAN;
  1842.     oldwp: e.APTR;
  1843. BEGIN
  1844.   result := f;
  1845.   oldwp := Me.windowPtr;
  1846.   Me.windowPtr := -1;
  1847.   lock := d.Lock(name,d.sharedLock);
  1848.   IF lock # NIL THEN
  1849.     result := w;
  1850.     d.UnLock(lock)
  1851.   END;
  1852.   Me.windowPtr := oldwp;
  1853.   RETURN result
  1854. END DirExists;
  1855.  
  1856.  
  1857.  
  1858. PROCEDURE Decrunch;
  1859.  
  1860. CONST
  1861.   tagBase    = u.user + ORD("X")*256 + ORD("P");
  1862.   inName     = tagBase+01H;
  1863.   inFH       = tagBase+02H;
  1864.   outName    = tagBase+10H;
  1865.   password   = tagBase+24H;
  1866.   getError   = tagBase+25H;
  1867.   shortError = tagBase+31H;
  1868.   typePacked = 1;
  1869.   flagsPassword = 0;
  1870.  
  1871. TYPE
  1872.   XpkFib = STRUCT
  1873.     type       : LONGINT;    (* Unpacked, packed, archive? *)
  1874.     uLen       : LONGINT;
  1875.     cLen       : LONGINT;
  1876.     nLen       : LONGINT;
  1877.     uCur       : LONGINT;
  1878.     cCur       : LONGINT;
  1879.     id         : LONGINT;
  1880.     packer     : ARRAY 6 OF CHAR;
  1881.     subVersion : INTEGER;
  1882.     masVersion : INTEGER;
  1883.     flags      : LONGSET;
  1884.     head       : ARRAY 16 OF CHAR;
  1885.     ratio      : LONGINT;
  1886.     reserved   : ARRAY 8 OF LONGINT;
  1887.   END;
  1888.  
  1889. VAR
  1890.   file: d.FileHandlePtr;
  1891.   err: LONGINT;
  1892.   xpkFib: XpkFib;
  1893.   errBuf: ARRAY 81 OF CHAR;
  1894.  
  1895.   PROCEDURE ExamineTags {xpk,-36}(VAR fib{8}  : XpkFib;
  1896.                                   tag1{9}..   : e.APTR): LONGINT;
  1897.   PROCEDURE UnpackTags  {xpk,-48}(tag1{8}..   : e.APTR): LONGINT;
  1898.  
  1899. BEGIN
  1900.   Decrunched := f;
  1901.   OldName := Name;
  1902.  
  1903.   IF DirExists("T:") THEN Name := "T:" ELSE Name := "RAM:" END;
  1904.  
  1905.   e.RawDoFmt("mm_%lx.decr",SYS.ADR(Me),StuffChar,SYS.ADR(Name[str.Length(Name)]));
  1906.  
  1907.   IF xpk=NIL THEN
  1908.     xpk := e.OpenLibrary("xpkmaster.library",1);
  1909.   END;
  1910.   IF xpk#NIL THEN
  1911.     err := ExamineTags(xpkFib,inFH,SYS.VAL(LONGINT,MyFile),u.done);
  1912.     IF (err#0) & (err#-20) THEN
  1913.       Request(LocStr(MSGOOM)^)
  1914.     END;
  1915.     IF (err=-20) OR (xpkFib.type#typePacked) THEN
  1916.       Name := OldName;
  1917.       RETURN
  1918.     END;
  1919.     Busy;
  1920.     err := UnpackTags(inFH,   SYS.VAL(LONGINT,MyFile),
  1921.                   outName,    SYS.ADR(Name),
  1922.                   password,   SYS.ADR(Password),
  1923.                   getError,   SYS.ADR(errBuf),
  1924.                   shortError, e.true,
  1925.                   u.done);
  1926.     UnBusy;
  1927.     IF err#0 THEN Request(errBuf) END;
  1928.     file := d.Open(Name,d.oldFile);
  1929.     IF file#NIL THEN
  1930.       Decrunched := w;
  1931.       d.OldClose(MyFile);
  1932.       MyFile := file;
  1933.       RETURN
  1934.     ELSE
  1935.       Request(LocStr(MSGCOF)^);
  1936.     END;
  1937.   END;
  1938.   Name := OldName;
  1939. END Decrunch;
  1940.  
  1941.  
  1942. (*-----------------  Screen Mode Requester:  ------------------------*)
  1943.  
  1944.  
  1945. PROCEDURE GetNode (VAR list: e.List; index: LONGINT): e.NodePtr;
  1946.   VAR n: e.NodePtr;
  1947. BEGIN
  1948.   n := list.head;
  1949.   WHILE index > 0 DO
  1950.     IF n.succ=NIL THEN RETURN NIL END;
  1951.     n := n.succ;
  1952.     DEC(index);
  1953.   END;
  1954.   RETURN n;
  1955. END GetNode;
  1956.  
  1957.  
  1958. PROCEDURE ScreenModeReq (VAR displayID : LONGINT): INTEGER;
  1959. CONST
  1960.   gadLISTVIEW    = 1;
  1961.   gadBUTTONSave  = 2;
  1962.   gadBUTTONUse   = 3;
  1963.   gadBUTTONCancel= 4;
  1964.  
  1965.   Topaz80 = g.TextAttr(SYS.ADR("topaz.font"), 8, SHORTSET{}, SHORTSET{});
  1966.  
  1967. TYPE
  1968.   MyNodePtr = UNTRACED POINTER TO MyNode;
  1969.   MyNode = STRUCT (node: e.Node)
  1970.              displayID: LONGINT;
  1971.            END;
  1972.  
  1973. VAR
  1974.   ng            : gt.NewGadget;
  1975.   gad,glist     : I.GadgetPtr;
  1976.   win           : I.WindowPtr;
  1977.   pub           : I.ScreenPtr;
  1978.   font          : g.TextAttrPtr;
  1979.   width,height  : INTEGER;
  1980.   txW,txH       : INTEGER;
  1981.   result,index  : INTEGER;
  1982.   firstindex    : INTEGER;
  1983.   topborder     : INTEGER;
  1984.   x1,x2,min     : INTEGER;
  1985.   terminated    : BOOLEAN;
  1986.   lvlist        : e.List;
  1987.   lvSelectedTag : LONGINT;
  1988.   vi            : e.APTR;
  1989.   imsg          : I.IntuiMessagePtr;
  1990.   node          : MyNodePtr;
  1991.   dispID        : LONGINT;
  1992.   displayInfo   : g.DisplayInfo;
  1993.   nameInfo      : g.NameInfo;
  1994.  
  1995.  
  1996.   PROCEDURE StrLen (str: e.STRPTR; min: INTEGER): INTEGER;
  1997.   VAR it: I.IntuiText;
  1998.       len: INTEGER;
  1999.   BEGIN
  2000.     (* $IFNOT ClearVars *)
  2001.     len := 0;
  2002.     it.leftEdge := 0; it.topEdge  := 0; it.frontPen := 0; it.backPen  := 0;
  2003.     it.drawMode := SHORTSET{}; it.nextText := NIL;
  2004.     (* $END *)
  2005.     IF str#NIL THEN
  2006.       it.iTextFont := font; it.iText := str;
  2007.       len := I.IntuiTextLength(it);
  2008.     END;
  2009.     IF len > min THEN RETURN len ELSE RETURN min END;
  2010.   END StrLen;
  2011.  
  2012. BEGIN
  2013.   (* $IFNOT ClearVars *)
  2014.   win := NIL; vi := NIL; glist := NIL; pub := NIL; result := 0;
  2015.   (* $END *)
  2016.  
  2017.   LOOP
  2018.     pub := I.LockPubScreen(NIL);         IF pub=NIL THEN EXIT END;
  2019.     vi  := gt.GetVisualInfo(pub,u.done); IF vi =NIL THEN EXIT END;
  2020.     topborder := pub.wBorTop + pub.font.ySize + 1;
  2021.  
  2022.     font := pub.font;
  2023.     txW := pub.rastPort.txWidth; txH := pub.rastPort.txHeight;
  2024.     width := txW * 36 + 16; height := txH * 8 + 32;
  2025.     IF ((width+pub.wBorLeft+pub.wBorRight) > pub.width) OR ((height+topborder+pub.wBorBottom) > pub.height) THEN
  2026.       font := SYS.ADR(Topaz80);
  2027.       txW := 8; txH := 8;
  2028.       width := 8 * 36 + 16; height := 8 * 8 + 32;
  2029.     END;
  2030.     min := txW * 6;
  2031.  
  2032.     gad := gt.CreateContext(glist);
  2033.  
  2034.     ng.textAttr := font;
  2035.     ng.visualInfo := vi;
  2036.     ng.userData := NIL;
  2037.  
  2038.     ng.leftEdge := 16;
  2039.     ng.height := txH+4;
  2040.     ng.topEdge := topborder+height-ng.height-5;
  2041.     ng.gadgetText := LocStr(MSGSAVE);
  2042.     ng.width := StrLen(ng.gadgetText,min)+8;
  2043.     ng.gadgetID := gadBUTTONSave;
  2044.     ng.flags := LONGSET{};
  2045.     x1 := ng.leftEdge+ng.width;
  2046.  
  2047.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2048.  
  2049.     ng.gadgetText := LocStr(MSGCANCEL);
  2050.     ng.width := StrLen(ng.gadgetText,min)+8;
  2051.     ng.leftEdge := width-ng.width-8;
  2052.     ng.gadgetID := gadBUTTONCancel;
  2053.     x2 := ng.leftEdge;
  2054.  
  2055.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2056.  
  2057.     ng.gadgetText := LocStr(MSGUSE);
  2058.     ng.width := StrLen(ng.gadgetText,min)+8;
  2059.     ng.leftEdge := (x1+x2-ng.width) DIV 2;
  2060.     ng.gadgetID := gadBUTTONUse;
  2061.  
  2062.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2063.  
  2064.     lvlist.head := SYS.ADR(lvlist.tail);
  2065.     lvlist.tail := NIL;
  2066.     lvlist.tailPred := SYS.ADR(lvlist.head);
  2067.  
  2068.     index := 0;
  2069.     firstindex := -1;
  2070.     dispID := g.NextDisplayInfo(g.invalidID);
  2071.  
  2072.     WHILE dispID # g.invalidID DO
  2073.       IF (g.GetDisplayInfoData(NIL,displayInfo,SIZE(displayInfo),g.dtagDisp,dispID) > 0) &
  2074.          (displayInfo.notAvailable = 0) &
  2075.          (LONGSET{g.isHAM,g.isExtraHalfBrite,g.isDualPF} * displayInfo.propertyFlags = LONGSET{}) &
  2076.          (g.GetDisplayInfoData(NIL,nameInfo,SIZE(nameInfo),g.dtagName,dispID) > 0)
  2077.       THEN
  2078.         SYS.ALLOCATE(node);
  2079.         IF node # NIL THEN
  2080.           SYS.ALLOCATE(node.node.name);
  2081.           IF node.node.name # NIL THEN
  2082.             COPY(nameInfo.name,node.node.name^);
  2083.             node.displayID := dispID;
  2084.             e.AddTail(lvlist, node);
  2085.             IF dispID=displayID THEN firstindex := index END;
  2086.             INC(index);
  2087.           ELSE
  2088.             EXIT
  2089.           END;
  2090.         ELSE
  2091.           EXIT
  2092.         END;
  2093.       END;
  2094.       dispID := g.NextDisplayInfo(dispID);
  2095.     END;
  2096.  
  2097.     ng.leftEdge := 16;
  2098.     ng.topEdge := txH+8+topborder;
  2099.     ng.width := width-25;
  2100.     ng.height := txH*6+15;
  2101.     ng.gadgetText := LocStr(MSGCHOOSESM);
  2102.     ng.gadgetID := gadLISTVIEW;
  2103.     ng.flags := LONGSET{gt.highLabel,gt.placeTextAbove};
  2104.  
  2105.     IF firstindex >= 0 THEN lvSelectedTag := gt.lvSelected
  2106.                        ELSE lvSelectedTag := u.ignore END;
  2107.  
  2108.     gad := gt.CreateGadget(gt.listViewKind, gad, ng,
  2109.                     gt.lvLabels,       SYS.ADR(lvlist),
  2110.                     gt.lvShowSelected, NIL,
  2111.                     gt.lvScrollWidth,  txW*2,
  2112.                     I.layoutaSpacing,  2,
  2113.                     lvSelectedTag,     firstindex,
  2114.                     u.done);
  2115.     IF gad = NIL THEN EXIT END;
  2116.  
  2117.     win := I.OpenWindowTagsA(NIL,
  2118.                              I.waLeft,        30,
  2119.                              I.waTop,         20,
  2120.                              I.waInnerWidth,  width,
  2121.                              I.waInnerHeight, height,
  2122.                              I.waTitle,       SYS.ADR(MuchText),
  2123.                              I.waFlags,       LONGSET{I.activate,I.windowDrag,I.windowDepth,I.simpleRefresh,I.rmbTrap},
  2124.                              I.waIDCMP,       gt.listViewIDCMP+gt.buttonIDCMP+LONGSET{I.gadgetUp,I.refreshWindow},
  2125.                              I.waCustomScreen,pub,
  2126.                              I.waGadgets,     glist,
  2127.                              u.done);
  2128.     IF win = NIL THEN EXIT END;
  2129.     gt.RefreshWindow(win, NIL);
  2130.  
  2131.     dispID := displayID;
  2132.     terminated := f;
  2133.  
  2134.     WHILE ~terminated DO
  2135.       e.WaitPort(win.userPort);
  2136.       LOOP
  2137.         IF terminated THEN EXIT END;
  2138.         imsg := gt.GetIMsg(win.userPort);
  2139.         IF imsg=NIL THEN EXIT END;
  2140.         gad := imsg.iAddress;
  2141.   
  2142.         IF I.gadgetUp IN imsg.class THEN
  2143.           CASE gad.gadgetID OF
  2144.           | gadBUTTONSave:   result := 1; displayID := dispID; terminated := w;
  2145.           | gadBUTTONUse:    result := 2; displayID := dispID; terminated := w;
  2146.           | gadBUTTONCancel: terminated := w;
  2147.           | gadLISTVIEW:     node := GetNode(lvlist,imsg.code);
  2148.                              IF node # NIL THEN dispID := node.displayID END;
  2149.           ELSE
  2150.           END;
  2151.         END;
  2152.  
  2153.         IF I.refreshWindow IN imsg.class THEN
  2154.           gt.BeginRefresh(win);
  2155.           gt.EndRefresh(win, I.LTRUE);
  2156.         END;
  2157.  
  2158.         gt.ReplyIMsg(imsg);
  2159.   
  2160.       END;
  2161.     END;
  2162.  
  2163.     EXIT
  2164.   END;
  2165.  
  2166.   IF win   # NIL THEN I.CloseWindow(win) END;
  2167.   IF glist # NIL THEN gt.FreeGadgets(glist) END;
  2168.   IF vi    # NIL THEN gt.FreeVisualInfo(vi) END;
  2169.   IF pub   # NIL THEN I.UnlockPubScreen(NIL,pub) END;
  2170.  
  2171.   RETURN result;
  2172. END ScreenModeReq;
  2173.  
  2174.  
  2175. (*-------------------------------------------------------------------------*)
  2176.  
  2177.  
  2178. PROCEDURE SavePrefs;
  2179.  
  2180. VAR
  2181.   lock: d.FileLockPtr;
  2182.  
  2183.   PROCEDURE SavePrefsName(name: StringPtr);
  2184.   VAR file: d.FileHandlePtr;
  2185.       l: LONGINT;
  2186.   BEGIN
  2187.     file := d.Open(name^,d.newFile);
  2188.     IF file # NIL THEN
  2189.       SYS.SETREG(0,d.Write(file,"FORM",4));
  2190.       l := 16;
  2191.       SYS.SETREG(0,d.Write(file,l,4));
  2192.       SYS.SETREG(0,d.Write(file,"MUMO",4));
  2193.       SYS.SETREG(0,d.Write(file,"DPID",4));
  2194.       l := 4;
  2195.       SYS.SETREG(0,d.Write(file,l,4));
  2196.       SYS.SETREG(0,d.Write(file,id,4));
  2197.       d.OldClose(file);
  2198.     END;
  2199.   END SavePrefsName;
  2200.  
  2201. BEGIN
  2202.   IF DirExists("ENV:") THEN
  2203.     IF ~DirExists("ENV:MuchMore") THEN
  2204.       lock := d.CreateDir("ENV:MuchMore");
  2205.       IF lock#NIL THEN d.UnLock(lock) END;
  2206.     END;
  2207.     SavePrefsName(SYS.ADR("ENV:MuchMore/MuchMore.prefs"))
  2208.   END;
  2209.   IF DirExists("ENVARC:") THEN
  2210.     IF ~DirExists("ENVARC:MuchMore") THEN
  2211.       lock := d.CreateDir("ENVARC:MuchMore");
  2212.       IF lock#NIL THEN d.UnLock(lock) END;
  2213.     END;
  2214.     SavePrefsName(SYS.ADR("ENVARC:MuchMore/MuchMore.prefs"))
  2215.   END;
  2216. END SavePrefs;
  2217.  
  2218.  
  2219. (*-------------------------------------------------------------------------*)
  2220.  
  2221.  
  2222. PROCEDURE LoadPrefs;
  2223.  
  2224. VAR file: d.FileHandlePtr;
  2225.     l,i,s: LONGINT;
  2226.     ok: BOOLEAN;
  2227.  
  2228. BEGIN
  2229.   file := NIL;
  2230.   IF DirExists("PROGDIR:") THEN
  2231.     file := d.Open("PROGDIR:MuchMore.prefs",d.oldFile);
  2232.   END;
  2233.   IF (file=NIL) & DirExists("ENV:") THEN
  2234.     file := d.Open("ENV:MuchMore/MuchMore.prefs",d.oldFile);
  2235.   END;
  2236.   IF file # NIL THEN
  2237.     LOOP
  2238.       IF (d.Read(file,i,4) <= 0)        OR
  2239.          (i # SYS.VAL(LONGINT,"FORM"))  OR
  2240.          (d.Read(file,s,4) <= 0)        OR
  2241.          (d.Read(file,i,4) <= 0)        OR
  2242.          (i # SYS.VAL(LONGINT,"MUMO"))    THEN EXIT END;
  2243.       WHILE w DO
  2244.         IF (d.Read(file,i,4) <= 0)      OR
  2245.            (d.Read(file,s,4) <= 0)        THEN EXIT END;
  2246.         IF ODD(s) THEN INC(s) END;
  2247.         IF (s=4) & (i=SYS.VAL(LONGINT,"DPID")) THEN
  2248.           SYS.SETREG(0,d.Read(file,id,4));
  2249.         ELSE
  2250.           IF s < 0 THEN EXIT END;
  2251.           SYS.SETREG(0,d.Seek(file,s,d.current));
  2252.         END;
  2253.       END;
  2254.  
  2255.       EXIT;
  2256.     END;
  2257.     d.OldClose(file);
  2258.   END;
  2259. END LoadPrefs;
  2260.  
  2261.  
  2262. (*------------------------  Get Tooltypes:  --------------------------*)
  2263.  
  2264.  
  2265. PROCEDURE ParseIcon(icon: DiskObjectPtr);
  2266. VAR tt: StringPtr;
  2267.  
  2268. BEGIN
  2269.   IF icon # NIL THEN
  2270.     tt := FindToolType(icon.toolTypes,"COLORS");     IF (tt # NIL) THEN COPY(tt^,Pens) END;
  2271.     tt := FindToolType(icon.toolTypes,"EXTRASPACE"); IF (tt # NIL) THEN spacing := SHORT(StrToInt(tt,10)) END;
  2272.     tt := FindToolType(icon.toolTypes,"FONT");       IF (tt # NIL) THEN COPY(tt^,FontName) END;
  2273.     tt := FindToolType(icon.toolTypes,"PASSWORD");   IF (tt # NIL) THEN COPY(tt^,Password) END;
  2274.     tt := FindToolType(icon.toolTypes,"NOOSCAN");    IF (tt # NIL) & (MatchToolValue(tt^,"TRUE")) THEN noOscan := w END;
  2275.     tt := FindToolType(icon.toolTypes,"OLDSTYLE");   IF (tt # NIL) & (MatchToolValue(tt^,"TRUE")) THEN oldstyle := w END;
  2276.     tt := FindToolType(icon.toolTypes,"PLANES");     IF (tt # NIL) THEN NuScreen.depth := SHORT(StrToInt(tt,10)) END;
  2277.     tt := FindToolType(icon.toolTypes,"SCROLLMODE"); IF (tt # NIL) THEN scrollmode := SHORT(StrToInt(tt,10)) END;
  2278.     tt := FindToolType(icon.toolTypes,"TABWIDTH");   IF (tt # NIL) THEN tabw := SHORT(StrToInt(tt,10)) END;
  2279.     tt := FindToolType(icon.toolTypes,"TOGGLELACE"); IF (tt # NIL) & (MatchToolValue(tt^,"TRUE")) THEN lace := ~lace END;
  2280.     tt := FindToolType(icon.toolTypes,"TOOLPRI");    IF (tt # NIL) THEN taskpri := SHORT(SHORT(StrToInt(tt,10))) END;
  2281.     FreeDiskObject(icon);
  2282.   END;
  2283. END ParseIcon;
  2284.  
  2285.  
  2286. (*------------------------------  MAIN:  ----------------------------------*)
  2287.  
  2288. BEGIN
  2289.  
  2290. (*------  Init:  ------*)
  2291.  
  2292.   mySigBit := -1;
  2293.   Me := SYS.VAL(d.ProcessPtr,ol.Me);
  2294.   OldDir := Me.currentDir;
  2295.   oldpri := Me.task.node.pri; taskpri := oldpri;
  2296.   WriteName := "PRT:";
  2297.   MemIndex := ChunkSize;
  2298.   Sync := w;
  2299.   FontSize := 8;
  2300.   Pattern := "~(#?.info)";
  2301.   id := g.invalidID;
  2302.   tabw := 8;
  2303.   NuScreen.depth := 2;
  2304.  
  2305.   IF g.gfx.libNode.version >= 37 THEN scrollmode := 1 END;
  2306.  
  2307.   I.GetPrefs(Prefs,SIZE(Prefs)); lace := Prefs.laceWB # SHORTSET{};
  2308.  
  2309.   mySigBit := e.AllocSignal(-1);
  2310.   IF mySigBit<0 THEN HALT(d.fail) END;
  2311.   mySig := LONGSET{mySigBit};
  2312.  
  2313.   iconBase := e.OpenLibrary("icon.library",33);
  2314.  
  2315.   IF loc.base # NIL THEN
  2316.     catalog := loc.OpenCatalog(NIL,"muchmore.catalog",u.end);
  2317.   END;
  2318.  
  2319.   ol.OutOfMemHandler := OutOfMemHandler;
  2320.  
  2321.   INCL(ol.MemReqs,e.public);
  2322.  
  2323.   ol.New(ShowStack,ShowStackSize);
  2324.   NEW(ShowTask);
  2325.   NEW(FileInfo);
  2326.   NEW(ievent);
  2327.   NEW(conreq);
  2328.   NEW(Buffer);
  2329.  
  2330. (*------  Setup:  ------*)
  2331.  
  2332.   NEW(FirstLine);
  2333. (*FirstLine.size := 0;
  2334.   FirstLine.text[0] := 0X; *)
  2335.  
  2336. (*------  Start:  ------*)
  2337.  
  2338.   LoadPrefs;
  2339.  
  2340.   IF ol.wbStarted THEN
  2341.  
  2342.     wbm := ol.wbenchMsg;
  2343.     IF iconBase # NIL THEN
  2344.       oldLace:=lace;
  2345.       j := SHORT(wbm.numArgs); IF j>2 THEN j := 2 END;
  2346.       FOR i := 0 TO j-1 DO
  2347.         lace := oldLace;
  2348.         SYS.SETREG(0,d.CurrentDir(wbm.argList[i].lock));
  2349.         nameptr := wbm.argList[i].name;
  2350.         icon := GetDiskObject(nameptr^);
  2351.         IF (icon=NIL) & (d.base.lib.version >= 37) THEN
  2352.           SYS.SETREG(0,d.CurrentDir(d.GetProgramDir()));
  2353.           icon := GetDiskObject(nameptr^);
  2354.         END;
  2355.         ParseIcon(icon);
  2356.       END;
  2357.     END; (* IF iconBase#NIL *)
  2358.  
  2359.     IF wbm.numArgs >= 2 THEN
  2360.       ArgPtr := wbm.argList^[1].name; Name := ArgPtr^;
  2361.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[1].lock));
  2362.     ELSE
  2363.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[0].lock));
  2364.       FileReq(Name)
  2365.     END;
  2366.  
  2367.   ELSE
  2368.  
  2369.     IF d.dos.lib.version < 37 THEN
  2370.       IF ol.dosCmdLen > 1 THEN
  2371.         CommLine := ol.dosCmdBuf;
  2372.         j := 0;
  2373.         LOOP
  2374.           i := 0;
  2375.           WHILE CommLine[j]=20X DO INC(j) END;
  2376.           IF CommLine[j]=0AX THEN EXIT END;
  2377.           IF CommLine[j]='"' THEN
  2378.             INC(j);
  2379.             LOOP
  2380.               CASE CommLine[j] OF
  2381.               | '"': INC(j); EXIT
  2382.               | 0AX:                     EXIT
  2383.               ELSE
  2384.                 option[i] := CommLine[j]; INC(i); INC(j);
  2385.               END;
  2386.             END;
  2387.           ELSE
  2388.             WHILE (CommLine[j]#0AX) & (CommLine[j]#20X) DO
  2389.               option[i] := CommLine[j]; INC(i); INC(j);
  2390.             END;
  2391.           END;
  2392.           option[i]:= 0X;
  2393.           IF option="?"  THEN Request(usage) END;
  2394.           IF option[0]="-" THEN
  2395.             CASE CAP(option[1]) OF
  2396.               "A": tabw := SHORT(StrToInt(SYS.ADR(option[2]),10)) |
  2397.               "B": NuScreen.depth := SHORT(StrToInt(SYS.ADR(option[2]),10)) |
  2398.               "C": GetStr(SYS.ADR(option[2]),Pens) |
  2399.               "E": spacing := SHORT(StrToInt(SYS.ADR(option[2]),10)) |
  2400.               "F": GetStr(SYS.ADR(option[2]),FontName) |
  2401.               "L": lace := ~lace |
  2402.               "O": oldstyle := w |
  2403.               "P": GetStr(SYS.ADR(option[2]),Password) |
  2404.               "S": scrollmode := SHORT(StrToInt(SYS.ADR(option[2]),10)) |
  2405.               "T": taskpri := SHORT(SHORT(StrToInt(SYS.ADR(option[2]),10))) |
  2406.             ELSE
  2407.               Request(usage);
  2408.             END;
  2409.           ELSE
  2410.             COPY(option,Name);
  2411.           END;
  2412.         END;
  2413.       END;
  2414.  
  2415.     ELSE  (* d.dos.lib.version >= 37 *)
  2416.  
  2417.       IF iconBase#NIL THEN
  2418.         oldcd := d.CurrentDir(d.GetProgramDir());
  2419.         IF d.GetProgramName(Name,LEN(Name)) THEN
  2420.           icon := GetDiskObject(Name);
  2421.           ParseIcon(icon);
  2422.           Name[0] := 0X;
  2423.         END;
  2424.         oldcd := d.CurrentDir(oldcd);
  2425.       END;
  2426.  
  2427.       rd := d.ReadArgs("A=TABWIDTH/N/K,B=PLANES/N/K,C=COLORS/K,D=DISPMODEREQ/S,E=EXTRASPACE/N/K,F=FONT/K,N=NOOSCAN/S,O=OLDSTYLE/S,P=PASSWORD/K,S=SCROLLMODE/N/K,T=TOOLPRI/N/K,FILE",args,NIL);
  2428.       IF rd=NIL THEN
  2429.         SYS.SETREG(0,d.PrintFault(d.IoErr(),NIL));
  2430.         HALT(d.warn)
  2431.       END;
  2432.       IF args.a # NIL THEN tabw := SHORT(args.a^) END;
  2433.       IF args.b # NIL THEN NuScreen.depth := SHORT(args.b^) END;
  2434.       IF args.c # NIL THEN COPY(args.c^,Pens) END;
  2435.       IF args.d # NIL THEN modeReq := w END;
  2436.       IF args.e # NIL THEN spacing := SHORT(args.e^) END;
  2437.       IF args.f # NIL THEN COPY(args.f^,FontName) END;
  2438.       IF args.n # NIL THEN noOscan := w END;
  2439.       IF args.o # NIL THEN oldstyle := w END;
  2440.       IF args.p # NIL THEN COPY(args.p^,Password) END;
  2441.       IF args.s # NIL THEN scrollmode := SHORT(args.s^) END;
  2442.       IF args.t # NIL THEN taskpri := SHORT(SHORT(args.t^)) END;
  2443.       IF args.file # NIL THEN COPY(args.file^,Name) END;
  2444.       d.FreeArgs(rd); rd := NIL;
  2445.     END;
  2446.   END;
  2447.  
  2448.   IF tabw < 1 THEN tabw := 1 END;
  2449.  
  2450.   IF NuScreen.depth < 1 THEN NuScreen.depth := 1 END;
  2451.   IF NuScreen.depth > 2 THEN NuScreen.depth := 2 END;
  2452.  
  2453.   IF taskpri#oldpri THEN SYS.SETREG(0,e.SetTaskPri(Me,taskpri)) END;
  2454.  
  2455.   IF FontName[0]#0X THEN
  2456.     i := 0;
  2457.     j := SHORT(str.Length(FontName));
  2458.     LOOP
  2459.       IF i >= j THEN EXIT END;
  2460.       IF FontName[i]='/' THEN
  2461.         FontName[i] := 0X;
  2462.         FontSize := SHORT(StrToInt(SYS.ADR(FontName[i+1]),10));
  2463.         j := i;
  2464.         EXIT
  2465.       END;
  2466.       INC(i);
  2467.     END;
  2468.     IF j<LEN(FontName)-6 THEN
  2469.       e.CopyMem(".font",FontName[j],6);
  2470.     END;
  2471.   END;
  2472.  
  2473.   IF FontSize>50 THEN FontSize := 50 END;
  2474.   IF FontSize< 5 THEN FontSize :=  5 END;
  2475.  
  2476.   IF spacing< 0 THEN spacing :=  0 END;
  2477.   IF spacing>20 THEN spacing := 20 END;
  2478.  
  2479.   IF modeReq & (gt.base#NIL) THEN
  2480.     IF ScreenModeReq(id) = 1 THEN SavePrefs END;
  2481.   END;
  2482.  
  2483. (*------  Open File:  ------*)
  2484.  
  2485.   LOOP
  2486.     MyFile := d.Open(Name,d.oldFile);
  2487.     IF MyFile#NIL THEN EXIT END;
  2488.     FileReq(Name)
  2489.   END;
  2490.  
  2491. (*------------------------  Open Display:  --------------------------------*)
  2492.  
  2493. (*------  Open Screen:  ------*)
  2494.  
  2495.   IF lace THEN
  2496.     NuScreen.viewModes := {g.hires,g.lace};
  2497.     NuScreen.height := g.gfx.normalDisplayRows*2
  2498.   ELSE
  2499.     NuScreen.viewModes := {g.hires};
  2500.     NuScreen.height := g.gfx.normalDisplayRows
  2501.   END;
  2502.   NuScreen.width  := g.gfx.normalDisplayColumns;
  2503.   NuScreen.type   := I.customScreen+{I.screenQuiet};
  2504.  
  2505.   LOOP
  2506.  
  2507.     IF I.int.libNode.version >= 37 THEN
  2508.  
  2509.       IF id=g.invalidID THEN
  2510.         id := g.defaultMonitorID;
  2511.         pub := I.LockPubScreen("Workbench");
  2512.         IF pub # NIL THEN
  2513.           id := g.GetVPModeID(SYS.ADR(pub.viewPort));
  2514.           I.UnlockPubScreen(NIL,pub);
  2515.         END;
  2516.       END;
  2517.  
  2518.       IF g.GetDisplayInfoData(NIL,dims,SIZE(dims),g.dtagDims,id) > 0 THEN
  2519.         IF noOscan THEN
  2520.           NuScreen.width     := dims.nominal.maxX - dims.nominal.minX + 1;
  2521.           NuScreen.height    := dims.nominal.maxY - dims.nominal.minY + 1;
  2522.           overscanTag := u.ignore;
  2523.         ELSE
  2524.           NuScreen.width     := dims.txtOScan.maxX - dims.txtOScan.minX + 1;
  2525.           NuScreen.height    := dims.txtOScan.maxY - dims.txtOScan.minY + 1;
  2526.           overscanTag := I.saOverscan;
  2527.         END;
  2528.         IF g.GetDisplayInfoData(NIL,disp,SIZE(disp),g.dtagDisp,id) > 0 THEN
  2529.           lace := g.isLace IN disp.propertyFlags;
  2530.           Scrollable := (g.isDraggable IN disp.propertyFlags) (* & ((g.gfx.libNode.version<39) OR ~(20 IN disp.propertyFlags)) *);
  2531.           IF scrollmode=3 THEN Scrollable := f END;
  2532.           IF Scrollable THEN INC(NuScreen.height,NuScreen.height) END;
  2533.  
  2534.           Screen := I.OpenScreenTags(NuScreen,
  2535.                                      I.saDisplayID,id,
  2536.                                      overscanTag,I.oScanText,
  2537.                                      I.saPens,SYS.ADR("\xFF\xFF"),
  2538.                                      u.end);
  2539.         END;
  2540.       END;
  2541.  
  2542.     ELSE
  2543.  
  2544.       Scrollable := w;
  2545.       IF scrollmode=3 THEN Scrollable := f END;
  2546.       IF Scrollable THEN INC(NuScreen.height,NuScreen.height) END;
  2547.       Screen := I.OpenScreen(NuScreen);
  2548.  
  2549.     END;
  2550.  
  2551.     IF Screen#NIL THEN EXIT END;
  2552.  
  2553.     DEC(NuScreen.depth);
  2554.     IF NuScreen.depth=0 THEN Request(LocStr(MSGCOS)^) END;
  2555.   END;
  2556.  
  2557.   numColors := ASH(LONG(1),NuScreen.depth);
  2558.  
  2559.   rp := SYS.ADR(Screen.rastPort);
  2560.   BM := rp.bitMap;
  2561.   ri := Screen.viewPort.rasInfo;
  2562.  
  2563.   IF Pens[0]#0X THEN
  2564.     i := 0;
  2565.     chptr := SYS.ADR(Pens);
  2566.     Pens[LEN(Pens)-1] := 0X;
  2567.     LOOP
  2568.       Cols[i] := SHORT(StrToInt(SYS.VAL(StringPtr,chptr),16));
  2569.       INC(i); IF i=4 THEN EXIT END;
  2570.       WHILE (chptr^#0X) & (chptr^#",") DO
  2571.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2572.       END;
  2573.       IF chptr^="," THEN
  2574.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2575.       ELSE
  2576.         EXIT
  2577.       END;
  2578.     END;
  2579.     g.LoadRGB4(SYS.ADR(Screen.viewPort),Cols,i);
  2580.   END;
  2581.  
  2582. (*------  Open Font:  ------*)
  2583.  
  2584.   IF FontName[0]#0X THEN
  2585.     MyAttr.name := SYS.ADR(FontName);
  2586.     MyAttr.ySize := FontSize;
  2587.     IF diskFontBase=NIL THEN diskFontBase := e.OpenLibrary("diskfont.library",33) END;
  2588.     IF diskFontBase#NIL THEN MyFont := OpenDiskFont(MyAttr) END;
  2589.     IF (MyFont#NIL) & ~(g.proportional IN MyFont.flags) THEN g.SetFont(rp,MyFont) END;
  2590.   END;
  2591.  
  2592.   LOOP
  2593.     fontWidth  := rp.font.xSize;
  2594.     fontHeight := rp.font.ySize;
  2595.     IF (fontWidth<=50) OR (fontHeight<=50) & (fontWidth>2) & (fontHeight>2) THEN EXIT END;
  2596.     MyAttr.name := SYS.ADR("topaz.font");
  2597.     MyAttr.ySize := 8;
  2598.     MyFont := g.OpenFont(MyAttr);
  2599.     IF MyFont=NIL THEN HALT(d.fail) END;
  2600.     g.SetFont(rp,MyFont);
  2601.   END;
  2602.   INC(fontHeight,spacing);               (* extra spacing *)
  2603.   fontBaseLine := rp.font.baseline;
  2604.  
  2605.   NumColumns := Screen.width DIV fontWidth;
  2606.   IF Scrollable THEN NumLines   := Screen.height DIV 2 DIV fontHeight;
  2607.                 ELSE NumLines   := Screen.height DIV fontHeight; END;
  2608.   PageHeight := fontHeight*NumLines;
  2609.  
  2610.   NuScreen.height := fontHeight*NumLines;
  2611.   NuScreen.width  := Screen.width;
  2612.  
  2613.   ClearBitMaps;
  2614.  
  2615.   IF Scrollable THEN
  2616.     Screen.height := NuScreen.height;
  2617.     I.MakeScreen(Screen);
  2618.     I.RethinkDisplay;
  2619.   END;
  2620.  
  2621. (*------  Open Window:  ------*)
  2622.  
  2623.   NuWindow.flags  := LONGSET{I.rmbTrap,I.activate,I.borderless,I.noCareRefresh,I.simpleRefresh,I.backDrop};
  2624.   NuWindow.screen := Screen;
  2625.   NuWindow.type   := I.customScreen;
  2626.   NuWindow.topEdge:= 10;
  2627.   NuWindow.width  := Screen.width;
  2628.   NuWindow.height := Screen.height-10;
  2629.   NuWindow.idcmpFlags := MyIdcmp;
  2630.   Window := I.OpenWindow(NuWindow);
  2631.   IF Window=NIL THEN Request(LocStr(MSGCOW)^) END;
  2632.  
  2633. (*------  Get KeyMap:  ------*)
  2634.  
  2635.   IF e.OpenDevice("console.device",-1,conreq,LONGSET{})#0 THEN HALT(d.fail) END;
  2636.   console := conreq.device;
  2637.   con.base := console;
  2638. (*ievent.nextEvent := NIL;
  2639.   ievent.qualifier := {};
  2640.   ievent.eventAddress := NIL; *)
  2641.   ievent.class := ie.rawkey;
  2642.  
  2643.   FOR i := 0 TO 3FH DO
  2644.     ievent.code := i;
  2645.     SYS.SETREG(0,con.RawKeyConvert(ievent,KeyMap[i],16,NIL));
  2646.   END;
  2647.  
  2648. (*------  Decrunch:  ------*)
  2649.  
  2650.   Decrunch;
  2651.  
  2652. (*------  Init 2nd Task:  ------*)
  2653.  
  2654.   ShowTask.spLower := ShowStack;
  2655.   ShowTask.spUpper := SYS.VAL(e.APTR,SYS.VAL(LONGINT,ShowStack) + ShowStackSize);
  2656.   ShowTask.spReg   := ShowTask.spUpper;
  2657.   ShowTask.node.type := e.task;
  2658.   ShowTask.node.name := SYS.ADR("mm.show");
  2659.   ShowTask.node.pri  := Me.task.node.pri+1;
  2660.   (* $IF SmallData *)
  2661.   ShowTask.userData  := SYS.REG(13);           (* VarBase *)
  2662.   (* $END *)
  2663.  
  2664.   e.Forbid;
  2665.    e.AddTask(ShowTask,ShowProc,NIL);
  2666.    ShowTaskRunning := w;
  2667.    Window.userPort.sigTask := ShowTask;
  2668.   e.Permit;
  2669.  
  2670. (*------  Main Load / Display Loop:  ------*)
  2671.  
  2672.   LOOP
  2673.     fg := 1; bg := 0; oldfg := fg; oldbg := bg; style := SHORTSET{};
  2674.     RQLen := -1; RQPos := -1;
  2675.     AnzLines := 1;
  2676.     LastLine := FirstLine;
  2677.     BottomLine := FirstLine;
  2678.     TopLine    := FirstLine;
  2679.     TextLength := 0;
  2680.     FindLine   := NIL;
  2681.     FOR i := 0 TO 9 DO TextMarkers[i] := NIL END;
  2682.  
  2683.     MyLock := d.Lock(Name,d.sharedLock);
  2684.     IF MyLock=NIL THEN Request(LocStr(MSGCOF)^) END;
  2685.     IF ~ d.Examine(MyLock,FileInfo^) THEN Request(LocStr(MSGCOF)^) END;
  2686.     FileLength := FileInfo.size;
  2687.  
  2688.     d.UnLock(MyLock); MyLock := NIL;
  2689.     IF FileLength=0 THEN Request(LocStr(MSGEMPTY)^) END;
  2690.  
  2691.     (*------  Start displaying & Loading:  ------*)
  2692.  
  2693.     NewDisp := w;
  2694.  
  2695.     e.Signal(ShowTask,mySig);
  2696.  
  2697.     REPEAT
  2698.       LoadLine := GetTextLine();
  2699.       IF LoadLine=NIL THEN
  2700.         d.OldClose(MyFile); MyFile := NIL;
  2701.       ELSE
  2702.         LoadLine.prev := LastLine;
  2703.         LastLine.next := LoadLine;
  2704.         LastLine := LoadLine;
  2705.       END;
  2706.       IF SignalNewData THEN e.Signal(ShowTask,mySig) END;
  2707.     UNTIL (MyFile=NIL) OR Done OR NewText;
  2708.     IF SignalAllRead THEN e.Signal(ShowTask,mySig) END;
  2709.     REPEAT
  2710.       SYS.SETREG(0,e.Wait(mySig));
  2711.       IF print THEN
  2712.         in := d.Open("NIL:",d.oldFile); out := d.Open("NIL:",d.newFile);
  2713.         SYS.SETREG(0,d.Execute(PStr,in,out));
  2714.         d.OldClose(in); in := NIL; d.OldClose(out); out := NIL; print := f;
  2715.       END;
  2716.       IF save THEN
  2717.         in := d.Open(Name,d.oldFile);
  2718.         IF in=NIL THEN I.DisplayBeep(NIL) ELSE
  2719.           ol.New(buffer,savesize);
  2720.           SYS.SETREG(0,d.Seek(in,savefrom,0));
  2721.           IF d.Read(in,buffer^,savesize)#savesize THEN
  2722.             I.DisplayBeep(NIL);
  2723.             d.OldClose(in); in := NIL;
  2724.           ELSE
  2725.             d.OldClose(in); in := NIL;
  2726.             IF copy THEN
  2727.               iff := NIL;
  2728.               LOOP
  2729.                 IF ip.base=NIL THEN EXIT END;
  2730.                 iff := ip.AllocIFF();
  2731.                 IF iff=NIL THEN EXIT END;
  2732.                 iff.stream := SYS.VAL(LONGINT,ip.OpenClipboard(0));
  2733.                 IF iff.stream=NIL THEN EXIT END;
  2734.                 ip.InitIFFasClip (iff);
  2735.                 IF (ip.OpenIFF  (iff, ip.write) = 0) &
  2736.                    (ip.PushChunk(iff, SYS.VAL(LONGINT,"FTXT"), ip.idFORM, ip.IFFSizeUnknown)=0) &
  2737.                    (ip.PushChunk(iff, 0, SYS.VAL(LONGINT,"CHRS"), ip.IFFSizeUnknown)=0) &
  2738.                    (ip.WriteChunkBytes(iff,buffer^,savesize) = savesize) &
  2739.                    (ip.PopChunk (iff)=0) &
  2740.                    (ip.PopChunk (iff)=0) THEN
  2741.                 END;
  2742.                 EXIT;
  2743.               END;
  2744.               IF iff#NIL THEN
  2745.                 ip.CloseIFF(iff);
  2746.                 IF iff.stream#0 THEN ip.CloseClipboard (SYS.VAL(e.APTR,iff.stream)) END;
  2747.                 ip.FreeIFF (iff);
  2748.               END;
  2749.             ELSE
  2750.               out := d.Open(WriteName,d.newFile);
  2751.               IF out=NIL THEN I.DisplayBeep(NIL) ELSE
  2752.                 IF d.Write(out,buffer^,savesize)#savesize THEN I.DisplayBeep(NIL) END;
  2753.                 d.OldClose(out); out := NIL;
  2754.               END;
  2755.             END;
  2756.           END;
  2757.           DISPOSE(buffer);
  2758.         END;
  2759.         save := f;
  2760.       END;
  2761.       IF Done THEN EXIT END;
  2762.     UNTIL NewText;
  2763.     IF MyFile#NIL THEN d.OldClose(MyFile); MyFile := NIL END;
  2764.     IF Decrunched & d.DeleteFile(Name) THEN END;
  2765.     Decrunched := f;
  2766.     DisposeLines();
  2767.     FirstLine^.next := NIL; NewText := f;
  2768.     Name := OldName;
  2769.     REPEAT
  2770.       FileReq(Name);
  2771.       MyFile := d.Open(Name,d.oldFile);
  2772.     UNTIL MyFile#NIL;
  2773.     Decrunch;
  2774.   END;   (* LOOP *)
  2775.  
  2776. CLOSE
  2777.  
  2778.   IF win         #NIL THEN I.CloseWindow(win)               END;
  2779.   IF ShowTaskRunning  THEN e.RemTask(ShowTask)              END;
  2780.   IF console     #NIL THEN e.CloseDevice(conreq)            END;
  2781.   IF Window      #NIL THEN I.CloseWindow(Window)            END;
  2782.   IF Screen      #NIL THEN I.OldCloseScreen(Screen)         END;
  2783.   IF MyFont      #NIL THEN g.CloseFont(MyFont)              END;
  2784.   IF MyFile      #NIL THEN d.OldClose(MyFile)               END;
  2785.   IF in          #NIL THEN d.OldClose(in)                   END;
  2786.   IF out         #NIL THEN d.OldClose(out)                  END;
  2787.   IF Decrunched       THEN SYS.SETREG(0,d.DeleteFile(Name)) END;
  2788.   IF MyLock      #NIL THEN d.UnLock(MyLock)                 END;
  2789.   IF xpk         #NIL THEN e.CloseLibrary(xpk)              END;
  2790.   IF arp         #NIL THEN e.CloseLibrary(arp)              END;
  2791.   IF asl         #NIL THEN e.CloseLibrary(asl)              END;
  2792.   IF diskFontBase#NIL THEN e.CloseLibrary(diskFontBase)     END;
  2793.   IF iconBase    #NIL THEN e.CloseLibrary(iconBase)         END;
  2794.   IF rd          #NIL THEN d.FreeArgs(rd)                   END;
  2795.   IF mySigBit>=0      THEN e.FreeSignal(mySigBit)           END;
  2796.   IF catalog     #NIL THEN loc.CloseCatalog(catalog);       END;
  2797.   IF taskpri  #oldpri THEN oldpri := e.SetTaskPri(Me,oldpri)END;
  2798.   OldDir := d.CurrentDir(OldDir);
  2799.  
  2800. END MuchMore.
  2801.  
  2802.